I am trying to run elastic search in rails project but getting an error:

[ERROR] There has been an error when creating the index -- elasticsearch returned:

405 : {"error":"Incorrect HTTP method for uri [/articles] and method [POST], allowed: [GET, DELETE, PUT, HEAD]","status":405}

[IMPORT] Deleting index 'articles' [IMPORT] Creating index 'articles' with mapping:

{"article":{"properties":{"title":{"type":"string"},"category_name":{"boost":10,"type":"string"}}}}

[ERROR] There has been an error when creating the index -- Elasticsearch returned:

405 : {"error":"Incorrect HTTP method for uri [/articles] and method [POST], allowed: [GET, DELETE, PUT, HEAD]","status":405}

Here is how my article model looks like:

include Tire::Model::Search
include Tire::Model::Callbacks

mapping do
 indexes :id, type: 'integer'
 # indexes :author_id, type: 'integer'
 indexes :title
 indexes :category_name, boost: 10
 indexes :content # analyzer: 'snowball'
 indexes :created_at, type: 'date'
 indexes :published_comments, type: 'integer'
end

def self.search(params)
 tire.search(page: params[:page], per_page: 2) do
 query do
   boolean do
     must { string params[:query], default_operator: "AND" } if params[:query].present?
     must { range :published_at, lte: Time.zone.now }
     must { term :author_id, params[:author_id] } if params[:author_id].present?
   end
end
sort { by :published_at, "desc" } if params[:query].blank?
facet "authors" do
  terms :author_id
end
# raise to_curl
end
end

Below is the form where i have the search box and button:

 <div class="col-6 col-md-5">
  <%= form_tag @articles_path,:html => {class: "input-group rounded"}, method: :get do %>
     <%= text_field_tag :query, params[:query],placholder: "Search the entire site",class: "form-control w-100 g-brd-secondary-light-v2 g-brd-primary--focus g-color-secondary-dark-v1 g-placeholder-secondary-dark-v1 g-bg-white g-font-weight-400 g-font-size-13 rounded g-px-20 g-py-12" %>
     <span class="input-group-addon g-brd-none g-py-0 g-pr-0">
       <%= submit_tag "Search", name: nil , class: "btn u-btn-white g-color-primary--hover g-bg-secondary g-font-weight-600 g-font-size-13 text-uppercase rounded g-py-12 g-px-20"%>
     </span>
  <% end %>
 </div>

please help what to do I have been working on the solution from more than one week.

I implemented this following the railscasts video: http://railscasts.com/episodes/307-elasticsearch-part-2

I am indexing elasticsearch with rails using :

rake environment tire:import CLASS=Article FORCE=true

I need to run it on the localhost:3000 itself and not on any /links but getting an error

Thanks in advance

0

There are 0 answers