ElasticSearch: obtaining individual scores from each query inside of a bool query

喜你入骨 提交于 2021-02-11 14:48:01

问题


Assume I have a compound bool query with various "must" and "should" statements that each may include different leaf queries including "multi-match" and "match_phrase" queries such as below.

How can I get the score from individual queries packed into a single query? I know one way could be to break it down into multiple queries, execute each, and then aggregate the results in code-level (not query-level). However, I suppose that is less efficient, plus, I lose sorting/pagination/.... features from ElasticSearch.

I think "Explanation API" is also not useful for me since it provides very low-level details of scoring (inefficient and hard to parse) while I just need to know the score for each specific leaf query (which I've also already named them)

If I'm wrong on any terminology (e.g. compound, leaf), please correct me. The big picture is how to obtain individual scores from each sub-query inside of a bool query.

PS: I came across Different score functions in bool query. However, it does not return the scores. If I wrap my queries in "function_score", I want the scoring to be default but obtain the individual scores in response to the query.

Please see the snippet below:

{
  "query": {
    "bool": {
      "must": [
        {
          "multi_match": {
            "query": "...",
            "fields": [
              "field1^3",
              "field2^5"
            ],
            "_name": "must1_mm",
            "boost": 3
          }
        }
      ],
      "should": [
        {
          "multi_match": {
            "query": "...",
            "fields": [
              "field3^2",
              "field4^5"
            ],
            "boost": 2,
            "_name": "should1_mm",
            "boost": 2
          }
        },
          {
          "match_phrase": {
            "field5": {
              "_name": "phrase1",
              "boost": 1.5,
              "query": "..."
            }
          }
        },
        {
          "match_phrase": {
            "field6": {
              "_name": "phrase2",
              "boost": 1,
              "query": "..."
            }
          }
        }
      ]
    }
  }
}```


来源:https://stackoverflow.com/questions/60470667/elasticsearch-obtaining-individual-scores-from-each-query-inside-of-a-bool-quer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!