Home > Blockchain >  Named multi_match query
Named multi_match query

Time:10-18

I need a hand here. I have a cross_fields multi_match query and I need to use named queries for each field. I can rewrite it into a bool/should match but then I dont know how to reproduce the cross_fields condition. Any idea? Thanks!

Multimatch query: Relevance OK, but no named queries

GET test_index/_search
{
  "query": {
    "multi_match": {
      "query": "example_query",
      "fields": ["name","lastname"],
      "type": "cross_fields"
    }
  }
}

Bool query: Named queries OK but bad relevance

GET test_index/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "match": {
            "name": {
              "query": "example query",
              "_name": "name_match"
            }
          }
        },
        {
          "match": {
            "latname": {
              "query": "example query",
              "_name": "latname_match"
            }
          }
        }
      ]
    }
  }
}

CodePudding user response:

How does using dismax with tie_breaker: 1.0 work for your ES index?

Something like this:

GET vehicle/_search
{
  "query": {
    "dis_max": {
      "tie_breaker": 1.0,
      "queries": [
        {
          "match": {
            "make": {
              "query": "Lamborghini",
              "_name": "make"
            }
          }
        },
        {
          "match": {
            "model": {
              "query": "Diablo",
              "_name": "model"
            }
          }
        }
      ]
    }
  }
}

The Dismax query is very similar to the multi_match query in that it compares scores across sub clauses/queries. The tie_breaker parameter controls how much losing/non-max fields contributed to the final summation of clause scores, any losing fields scores are multiplied by the tie_breaker. The default tie_breaker: 0.0, which is most similar to type: best_fields in multi_match.

  • Related