ElasticSearch:结合多匹配类型有意义吗

g2ieeal7  于 2023-04-29  发布在  ElasticSearch
关注(0)|答案(1)|浏览(156)

如果我尝试使用3个不同的多匹配子查询进行搜索:best_fields、cross_fields和bool_prefix,ElasticSearch如何聚合或合并每个子查询的文档分数?这有意义吗

GET my_idx/_search
{
  "query": {
    "dis_max": {
      "tie_breaker": 0.7,
      "queries": [            
        {
          "bool": {
            "should": [
              {
                "multi_match": {
                  "query": "my keywords",
                  "fields": [
                    "fieldA.text^10",
                    "fieldB.text^5",
                    "fieldC.text^2"
                  ],
                  "type": "best_fields",
                  "operator": "AND",
                  "analyzer" :"my_analyzer",                      
                  "boost": 1.0
                }
              },
              {
                "nested": {
                  "path": "fieldArrayA",
                  "query" :
                  {
                    "multi_match": {
                      "query": "my keywords",
                      "type": "best_fields",
                      "operator": "and",
                      "fields": [
                        "fieldArrayA.email.text^5",
                        "fieldArrayA.phone.text^4",
                        "fieldArrayA.name.text"                            
                      ]
                    }
                  }
                }
              }
            ],               
            "minimum_should_match": 1
          }
        },
        {
          "bool": {
            "should": [
              {
                 "multi_match": {
                  "query": "my keywords",
                  "fields": [
                    "fieldA.text^10",
                    "fieldB.text^5",
                    "fieldC.text^2"
                  ],
                  "type": "bool_prefix",
                  "operator": "AND",
                  "analyzer" :"my_analyzer",                      
                  "boost": 1.0
                }
              },
              {
                "nested": {
                  "path": "fieldArrayA",
                  "query" :
                  {
                    "multi_match": {
                      "query": "my keywords",
                      "type": "best_fields",
                      "operator": "and",
                      "fields": [
                        "fieldArrayA.email.text^5",
                        "fieldArrayA.phone.text^4",
                        "fieldArrayA.name.text"                            
                      ]
                    }
                  }
                }
              }
            ],
            "minimum_should_match": 1
          }
        },
        {
          "bool": {
            "should": [
              {
                 "multi_match": {
                  "query": "my keywords",
                  "fields": [
                    "fieldA.text^10",
                    "fieldB.text^5",
                    "fieldC.text^2"
                  ],
                  "type": "cross_fields",
                  "operator": "AND",
                  "analyzer" :"my_analyzer",                      
                  "boost": 1.0
                }
              },
              {
                "nested": {
                  "path": "fieldArrayA",
                  "query" :
                  {
                    "multi_match": {
                      "query": "my keywords",
                      "type": "cross_fields",
                      "operator": "and",
                      "fields": [
                        "fieldArrayA.email.text^5",
                        "fieldArrayA.phone.text^4",
                        "fieldArrayA.name.text"                            
                      ]
                    }
                  }
                }
              }
            ],
            "minimum_should_match": 1
          }
        }
      ]
    }
  },
  "from": "0",
  "size": "1000"
}

我看了文档https://www.elastic.co/guide/en/elasticsearch//reference/current/query-dsl-multi-match-query.html#type-best-fields,但是它如何通过组合不同类型的多匹配查询来工作呢?谢谢!

kdfy810k

kdfy810k1#

当您发送查询时,elasticsearch会合并该查询。您可以使用explain API来了解它是如何工作的。

GET /my-index-000001/_search
{
  "explain": true,
  "query" : {
    "match" : { "message" : "GET /search" }
  }
}

此外,您还可以研究如何使用profile API进行评分。

GET /my-index-000001/_search
{
  "profile": true,
  "query" : {
    "match" : { "message" : "GET /search" }
  }
}

相关问题