【问题标题】:How can I get the score of the underlying matching query in a bool query in ElasticSearch?如何在 ElasticSearch 的布尔查询中获得底层匹配查询的分数?
【发布时间】:2015-05-15 03:19:39
【问题描述】:

我有一个非常复杂的搜索,我实际上是在执行大量搜索,以查找与一组许多实体中的至少一个实体匹配的文章。

我注意到,随着我添加更多实体,分数会发生巨大变化,因为我的 should 子句会变大。

这是我查询 2 个实体的示例:

{
  "size": 50,
  "track_scores": true,
  "min_score": 0.05,
  "sort": [
    {
      "timestamp": {
        "order": "desc"
      }
    }
  ],
  "query": {
    "bool": {
      "should": [
        {
          "bool": {
            "should": [
              {
                "function_score": {
                  "functions": [
                    {
                      "boost_factor": 1000000
                    }
                  ],
                  "query": {
                    "terms": {
                      "relatedProfiles": [
                        "SomethingElse/124026966662",
                        "SomeLocation/707765"
                      ]
                    }
                  },
                  "boost_mode": "replace"
                }
              },
              {
                "bool": {
                  "should": [
                    {
                      "multi_match": {
                        "type": "phrase",
                        "query": "Generic Systems",
                        "operator": "and",
                        "fields": [
                          "content.title",
                          "content.description"
                        ]
                      }
                    },
                    {
                      "multi_match": {
                        "type": "phrase",
                        "query": "Generic Systems, Inc.",
                        "operator": "and",
                        "fields": [
                          "content.title",
                          "content.description"
                        ]
                      }
                    }
                  ],
                  "minimum_should_match": "1"
                }
              }
            ],
            "minimum_should_match": "1",
            "_name": "0e7da739-1d18-448b-caa2-5c615a59d108"
          }
        },
        {
          "bool": {
            "should": [
              {
                "function_score": {
                  "functions": [
                    {
                      "boost_factor": 1000000
                    }
                  ],
                  "query": {
                    "terms": {
                      "relatedProfiles": [
                        "SomeLocation/162479",
                        "SomethingElse/32b95cc3-a363-47c3-2ac1-86fdb3b7d108"
                      ]
                    }
                  },
                  "boost_mode": "replace"
                }
              },
              {
                "bool": {
                  "should": [
                    {
                      "multi_match": {
                        "type": "phrase",
                        "query": "SomeBusiness Computer Inc",
                        "operator": "and",
                        "fields": [
                          "content.title",
                          "content.description"
                        ]
                      }
                    },
                    {
                      "multi_match": {
                        "type": "phrase",
                        "query": "SomeBusiness, Inc",
                        "operator": "and",
                        "fields": [
                          "content.title",
                          "content.description"
                        ]
                      }
                    }
                  ],
                  "minimum_should_match": "1"
                }
              }
            ],
            "minimum_should_match": "1",
            "_name": "00cc4b36-ce6b-4816-e61e-b7124344d108"
          }
        }
      ],
      "minimum_should_match": "1"
    }
  },
  "filter": {
    "bool": {
      "must": [
        {
          "bool": {
            "should": [
              {
                "bool": {
                  "must": [
                    {
                      "term": {
                        "type": "News"
                      }
                    },
                    {
                      "terms": {
                        "language": [
                          "eng"
                        ]
                      }
                    }
                  ]
                }
              },
              {
                "terms": {
                  "type": [
                    "Social",
                    "Job",
                    "Unknown"
                  ]
                }
              }
            ]
          }
        },
        {
          "range": {
            "timestamp": {
              "lt": "2015-05-13T09:25:40.605",
              "gt": "2013-05-13T09:25:40.605"
            }
          }
        }
      ]
    }
  }
}

我怎样才能让基础匹配成为分数?或者,至少是名称查询下方部分的分数?

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    也许https://elastic.co/webinars/elasticsearch-query-dsl 有一些见解;稍后在视频中,他谈到了 Dis Max Query

    来自https://www.elastic.co/guide/en/elasticsearch/reference/1.5/query-dsl-dis-max-query.html

    “我们希望主分数是与最高提升相关联的分数,而不是字段分数的总和(如布尔查询所给出的那样)。”

    【讨论】:

    • 毕竟是 Dis Max 查询!
    【解决方案2】:

    您可以为此使用explain API。在提供查询时,它会为每个文档匹配提供大量信息,说明该分数是如何推导出来的。它是调试分数的完美工具。

    【讨论】:

    猜你喜欢
    • 2016-05-15
    • 1970-01-01
    • 2017-09-18
    • 1970-01-01
    • 1970-01-01
    • 2017-05-22
    • 1970-01-01
    • 2016-03-23
    • 2021-09-12
    相关资源
    最近更新 更多