Setting Elasticsearch analyzer for specific field using tire gem

I have a Resource object that has the following fields: title, description, and body.

Using the tire gem I want to use a standard analyzer for title and description, but for the body field I want to use the snowball analyzer.

So In my resource.rb file I have the following code:

mapping do
  indexes :title, type: 'string', :index => :not_analyzed, :store => true
  indexes :description, type: 'string'
  indexes :body, type: 'string', :analyzer => 'snowball'

  search_query = params[:query] params[:page], per_page: 15) do |s|
    s.query { string params[:query], default_operator: "AND"} if params[:query].present?
    # do i need another line here specifically for description?
    #s.query { string "body:#{params[:query]}", analyzer: 'snowball'} if params[:query].present?

I set the analyzer in the mapping to snowball. And I verify that this works because if I run the following command:

curl -XGET localhost:9200/example/_search?q=body:cook

It will return cooking, cooked, etc.

However I want to be able to pass the following query

curl -XGET localhost:9200/example/_search?q=cooking

And I want elasticsearch to search for the word cooking in the title and description fields and search for the word cook in the body.

Is this possible? And because I'm new to this whole searching game, is this even a good idea? Or am I a guy just juggling cans of gasoline over a fire pit?

asked Apr 19, 2015 in Elasticsearch-php by rajesh
0 votes

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.