如何在ElasticSearch中的bool查询中获取基础匹配查询的分数?

时间:2015-05-15 03:19:40

标签: elasticsearch

我有一个非常复杂的搜索,我实际上是在搜索与一组多个实体中至少一个实体匹配的文章。

我注意到,当我添加更多实体时,得分会发生显着变化,因为我的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"
            }
          }
        }
      ]
    }
  }
}

如何才能将基础比赛作为分数?或者,至少,名称查询下面的部分得分?

2 个答案:

答案 0 :(得分:1)

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

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

  

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

答案 1 :(得分:0)

您可以使用explain API。在提供查询时,它为每个文档匹配提供了大量有关如何推断得分的信息。它是调试分数的完美工具。