I have a few very specific questions about Rails + Tire + ElasticSearch.
I have watched the Railscast about it, and I have read a lot of documentation but to be honest it is over my head. I would love someone to help me understand the finer points that I can't quite grasp.
Here is Resource.rb elasticsearch portion from my model:
include Tire::Model::Search
include Tire::Model::Callbacks
mapping do
indexes :url
indexes :title, :boost => 3
indexes :description, :boost => 2
indexes :category, :boost => 1.5, type: 'object',
properties: {
name: { type: 'multi_field',
fields: { name: { type: 'string', analyzer: 'keyword' } } } }
indexes :user, type: 'object',
properties: {
username: { type: 'multi_field',
fields: { username: { type: 'string', analyzer: 'keyword' } } } }
end
def self.elasticsearch(params)
tire.search(load: true, page: params[:page], per_page: 20) do
query { string params[:e], default_operator: "OR" } if params[:e].present?
end
end
def to_indexed_json
to_json( include: { user: { only: [:username] },
category: { only: [:name] }
} )
end
- What does 'not_analyzed' mean? On many of the tutorials I'm reading, they use this. If it's not analyzed, why is it included in the
mapping do
? - What is the purpose of using indexes. For example, something like
indexes :id, type: 'integer'
. Why would an integer need to be indexed, does that help with performance or something? - How do I modify the analyzer for the URL so it works better? For example if its stored as
http://www.dropbox.com
, searchingdropbox.com
doesn't find a result, butwww.dropbox.com
does. I have tried pasting in all the different analyzers and none of them really work for the URL - If my
category.name
is stored as plural, e.g 'books', 'movies', 'tapes', how can I tell the analyzer to look at this word based on singular as well as plural. Searching for 'movie' doesnt work, however 'movies' does work - When I remove
load: true
, my entire site breaks. He went over this in the railscast but only for a moment. Does that mean I need to move EVERY attribute (and association) into the mapping, and change it to :not_analyzed? (I just realized... maybe I just answered my own question #1!). - In general, what type of data works best for OR and which works best for AND? I'm thinking or seems more lenient as far as getting more results