簡體   English   中英

累計分數以進行多個單詞過濾

[英]Totalizing scores for multiple words filtering

我正在使用一個文檔查找器,該文檔查找器輸入N個單詞,並且應該搜索擊中同一列的所有N個單詞。 這N個單詞是有序的,如果第一個單詞和第二個單詞匹配不同的文檔,則第一個單詞匹配的文檔將需要更高的評分。 到目前為止,我已經知道了:

{
"from": 0, 
"query": {
    "custom_filters_score": {
        "filters": [
            {
                "boost": 10, 
                "filter": {
                    "term": {
                        "descripcion": "lost"
                    }
                }
            }, 
            {
                "boost": 9, 
                "filter": {
                    "term": {
                        "format": "in"
                    }
                }
            }
        ], 
    "query":{...(mandatory conditions regardless of the search pattenrs)...}}
    }
} 
}

在某種意義上說,如果它與第一個單詞匹配,它將比第二個單詞提升得更高。 但是,問題是我需要,如果它與第一個單詞和第二個單詞都匹配,則總得分就是兩個過濾器的總和,而不僅僅是最高得分。 在上面的示例中,包含描述的文檔:“空間丟失”的得分應高於包含“空間丟失”的得分。

我是否需要對腳本中兩個過濾器的分數求和? 如果是這樣,怎么辦?

謝謝!

您可以使用elasticsearch 0.90.4嗎? 如果是這樣,則不建議使用custom_filters_score並將其替換為[功能分數查詢] [1]: http : //www.elasticsearch.org/guide/zh-cn/elasticsearch/reference/current/query-dsl-function-score-query.html

使用功能分數查詢,您可以指定分數求和:

{
  "from": 0, 
  "query": {
    "function_score": {
        "functions" : [
            {
                "boost": 10, 
                "filter": {
                    "term": {
                        "descripcion": "lost"
                    }
                }
            }, 
            {
                "boost": 9, 
                "filter": {
                    "term": {
                        "format": "in"
                    }
                }
            }
        ], 
        "query":{...(mandatory conditions regardless of the search pattenrs)...},
        "score_mode" : "sum"
    }
  } 
}

暫無
暫無

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

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