Home > other >  How to apply fuzziness in a multi_match query to only specified fields in elasticsearch?
How to apply fuzziness in a multi_match query to only specified fields in elasticsearch?

Time:01-27

If I have a search query like below:

query: {
          multi_match: {
            query: searchQry,
            fields: ["field1", "field2", "field3"],
            fuzziness: 2,
            fuzzy_transpositions: true,
          },
        },

How am I able to apply fuzziness only on selective fields such as "field1" or "field2" or "field1" and "field3" instead of all of them, which is the standard behaviour?

CodePudding user response:

Using MultiMatch is not possible.

You can mix multi-match with matches with separated fuzziness.

Example:

{
  "query": {
    "bool": {
      "should": [
        {
          "multi_match": {
            "query": "xpto",
            "fields": [
              "field1",
              "field2"
            ]
          }
        },
        {
          "match": {
            "fiedl1": {
              "query": "xpto",
              "fuzziness": 1
            }
          }
        },
        {
          "match": {
            "fiedl2": {
              "query": "xpto",
              "fuzziness": 2
            }
          }
        }
      ]
    }
  }
}
  • Related