How do return exact term matching irrespective of order?

Hi community, appreciate if anyone has any insights on this.

We want to return only exact matches irrespective of the order of the terms, and disregard any terms that are not in the query.

For example, if we search "New York" or "York New", it should return "New York", but not "New York City".

Thanks!

is it really not possible for elasticsearch to allow exact term matching while ignoring order? it seems strange because its such a simple query

Maybe

POST product/_search
{
  "query": {
    "match_phrase": {
      "field_name": "New York"
    }
  }
}

Or

POST product/_search
{
  "query": {
    "bool": {
      "must": [
        { "term": { "field_name": "New" }},
        { "term": { "field_name": "York" }}
      ],
      "filter": [
        { "term": { "other_field": "value" }}   // Additional filter conditions, if needed
      ]
    }
  }
}

thank you. what I did was to index with a token_count, then add a .length filter and it works, but I was hoping for a more efficient solution without having to use token_count

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.