elasticsearchmatch-phrase

How to boost a phrase matching but just in certain field?


I want to boost a query if its by match phrasing but I want it to search only in a certain field. So far I have the following query

{
  "query": {
    "bool": {
      "should": [
        {
          "match_phrase": {
            "_all": {
              "query": "string",
              "boost": 5
            }
          }
        }
      ]
    }
  }
}

but this returns several results since I'm not specifying the field where it should search in. I tried this other approach:

{
  "query": {
    "bool": {
      "should": [
        {
          "match_phrase": {
            "_all": {
              "query": "string",
              "fields": [
                "filed_name"
              ],
              "boost": 5
            }
          }
        }
      ]
    }
  }
}

but I get the error

[match] query does not support [fields]]


Solution

  • You can use multi match query and use phrase type to do match_phrase in specific fields.

    {
      "query": {
        "multi_match": {
          "query": "some string",
          "fields": ["title","summary"],
          "type": "phrase"
        }
      }
    }