I have a Elasticsearch::Model
on a ActiveRecord::Base
model that looks like this
class ArtistGroup < ActiveRecord::Base
include Elasticsearch::Model
include Elasticsearch::Model::Callbacks
FT_REDIS_KEY = "agft"
has_many :artists
settings index: { number_of_shards: 5 } do
mappings dynamic: 'false' do
indexes :normalized_name, analyzer: 'english'
indexes :name, analyzer: 'english'
end
end
def as_indexed_json(options={})
as_json(only: ['normalized_name', 'id', 'name'])
end
....
When I search by .search('haim')
I want the document with name: "Haim" to be returned first before others like "Danielle Haim of Haim", how can I control ES querying to score by closest match?
Elasticsearch returns by default the results sorted by relevance (ie the score of each document).
The way that this score is calculated is based on a set of basic rules combined with some query-specific rules.
The standard similarity algorithm used in Elasticsearch is known as term frequency/inverse document frequency, or TF/IDF, which takes the following factors into account:
Individual queries may combine the TF/IDF score with other factors such as the term proximity in phrase queries, or term similarity in fuzzy queries.
For a complete description of relevance please refer here: http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/sorting.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.