toch
toch

Reputation: 67

ElasticSearch : combining multimatch types does make sense?

If I try to search with 3 differents multimatch sub-queries : best_fields, cross_fields and bool_prefix, How Does ElasticSearch to aggregate or to combine document scores from each sub-queries ? Does it even make sense ?

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"
}

I read the documentation https://www.elastic.co/guide/en/elasticsearch//reference/current/query-dsl-multi-match-query.html#type-best-fields, but how does it work by combining different types of multi-match queries? Thanks !

Upvotes: 0

Views: 99

Answers (1)

Musab Dogan
Musab Dogan

Reputation: 3580

When you send a query elasticsearch will combine that query. You can use the explain API to understand how it works.

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

Also, you can investigate how scoring works with the profile API.

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

Upvotes: 0

Related Questions