簡體   English   中英

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

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

我正在嘗試按2個字段對ES結果進行排序:可搜索和年份。

我的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

查詢:

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

查詢中有趣的事情:

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

我認為該查詢與2種參數配合得很好。 我的問題是,具有相同名稱(可搜索字段)的2個文檔的得分不同。

例如,我正在搜索“酒廠”:

在此處輸入圖片說明

即使可搜索字段相同,也會看到非常不同的分數。 我認為問題是由於ID字段(實際上是UUID)造成的。 看起來此ID字段會影響得分。 但是在我的架構映射中,我寫道不應對ID進行分析,並且在我的ES查詢中,我要求僅在“可搜索”字段中進行搜索,而不是在ID中進行搜索。

我在數學上錯過了相同領域相同分數的東西嗎? (實際上,按得分后的年份排序是沒有用的,因為相同字段的cos得分不同)

分數是不同的,因為它們是針對每個分片獨立計算的。 有關更多信息, 請參見此處

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM