简体   繁体   English

elasticsearch按分数排序-可搜索相同字段但分数不同?

[英]elasticsearch sort by score - same field searchable but score different?

I'm trying to sort my ES results by 2 fields: searchable and year. 我正在尝试按2个字段对ES结果进行排序:可搜索和年份。

The mapping in my Rails app: 我的Rails应用中的映射:

# mapping
  def as_indexed_json(options={}) 
    as_json(only: [:id, :searchable, :year]) 
  end 

  settings index: { number_of_shards: 5, number_of_replicas: 1 } do
    mapping do
      indexes :id, index: :not_analyzed
      indexes :searchable
      indexes :year
    end
  end

The query: 查询:

 @records = Wine.search(query: {match: {searchable: {query:params[:search], fuzziness:2, prefix_length:1}}}, sort: {_score: {order: :desc}, year: {order: :desc}}, size:100)

The interesting thing in the query: 查询中有趣的事情:

sort: {_score: {order: :desc}, year: {order: :desc}}

I think the query is working well with the 2 sort params. 我认为该查询与2种参数配合得很好。 My problem is the score is not the same for 2 documents with the same name (searchable field). 我的问题是,具有相同名称(可搜索字段)的2个文档的得分不同。

For example, I'm searching for "winery": 例如,我正在搜索“酒厂”:

在此处输入图片说明

You can see a very different score, even if the searchable field is the same. 即使可搜索字段相同,也会看到非常不同的分数。 I think the issue is due to the ID field (it's an UUID in fact). 我认为问题是由于ID字段(实际上是UUID)造成的。 Looks like this ID field influences the score. 看起来此ID字段会影响得分。 But in my schema mapping, I wrote that ID should not be analyzed and in my ES query, I ask to search ONLY in "searchable" field, not in ID too. 但是在我的架构映射中,我写道不应对ID进行分析,并且在我的ES查询中,我要求仅在“可搜索”字段中进行搜索,而不是在ID中进行搜索。

What did I miss to math the same score for same fields ? 我在数学上错过了相同领域相同分数的东西吗? (actually, sorting by year after score is not useful cos' scores are different for same fields) (实际上,按得分后的年份排序是没有用的,因为相同字段的cos得分不同)

Scores are different, because they are calculated independently for each shard. 分数是不同的,因为它们是针对每个分片独立计算的。 See here for more info. 有关更多信息, 请参见此处

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM