# How do return exact term matching irrespective of order?

**URL:** <https://discuss.elastic.co/t/how-do-return-exact-term-matching-irrespective-of-order/338297>\
**Category:** Elasticsearch\
**Created:** [July 13, 2023, 8:53am UTC](https://discuss.elastic.co/t/how-do-return-exact-term-matching-irrespective-of-order/338297 "2023-07-13T08:53:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![at\_ohn](https://avatars.discourse-cdn.com/v4/letter/a/bbe5ce/32.png) [@at\_ohn](https://discuss.elastic.co/u/at_ohn)\
**Post date:** [July 13, 2023, 8:53am UTC](https://discuss.elastic.co/t/how-do-return-exact-term-matching-irrespective-of-order/338297/1 "2023-07-13T08:53:59Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![at\_ohn](https://avatars.discourse-cdn.com/v4/letter/a/bbe5ce/32.png) [@at\_ohn](https://discuss.elastic.co/u/at_ohn)\
**Post date:** [July 14, 2023, 7:19am UTC](https://discuss.elastic.co/t/how-do-return-exact-term-matching-irrespective-of-order/338297/2 "2023-07-14T07:19:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![PodarcisMuralis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/podarcismuralis/32/122606_2.png) [@PodarcisMuralis](https://discuss.elastic.co/u/PodarcisMuralis)\
**Post date:** [July 14, 2023, 9:20pm UTC](https://discuss.elastic.co/t/how-do-return-exact-term-matching-irrespective-of-order/338297/3 "2023-07-14T21:20:06Z")

</div>

Maybe

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

```

Or

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

```

---

<div class="post-metadata">

**Author:** ![at\_ohn](https://avatars.discourse-cdn.com/v4/letter/a/bbe5ce/32.png) [@at\_ohn](https://discuss.elastic.co/u/at_ohn)\
**Post date:** [July 15, 2023, 6:30am UTC](https://discuss.elastic.co/t/how-do-return-exact-term-matching-irrespective-of-order/338297/4 "2023-07-15T06:30:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 12, 2023, 6:30am UTC](https://discuss.elastic.co/t/how-do-return-exact-term-matching-irrespective-of-order/338297/5 "2023-08-12T06:30:28Z")

</div>

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