# Match query with specific order of terms

**URL:** <https://discuss.elastic.co/t/match-query-with-specific-order-of-terms/328936>\
**Category:** Elasticsearch\
**Created:** [March 30, 2023, 12:38pm UTC](https://discuss.elastic.co/t/match-query-with-specific-order-of-terms/328936 "2023-03-30T12:38:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafael\_Kubina](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rafael_kubina/32/83691_2.png) [@Rafael\_Kubina](https://discuss.elastic.co/u/Rafael_Kubina)\
**Post date:** [March 30, 2023, 12:38pm UTC](https://discuss.elastic.co/t/match-query-with-specific-order-of-terms/328936/1 "2023-03-30T12:38:45Z")

</div>

We need to match a set of terms in a field while taking the order into account.

Example:  
The document:

```auto
{
  "my_field": "foo bar"
}

```

It should match when the user search for  
`foo bar`, `foo bar baz` or `baz foo bar`  
but not if the terms are in a different order  
`bar foo`, `bar foo baz` or `baz bar foo`

Using the match query with a `minimum_should_match` yields better results than without, but the wrong order of terms is matching too.

```auto
POST _search
{
  "query": {
    "match": {
      "my_field": {
        "query":"foo bar baz",
        "minimum_should_match": "2"
      }
    }
  }
}

```

Using the match\_phrase query is not working, as the users input contain more/other terms too.

```auto
POST _search
{
  "query": {
    "match_phrase": {
      "my_field": "foo bar baz"
    }
  }
}

```

Any Ideas?

Cheers!

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [March 30, 2023, 2:09pm UTC](https://discuss.elastic.co/t/match-query-with-specific-order-of-terms/328936/2 "2023-03-30T14:09:14Z")

</div>

Hi @Rafael_Kubina

I dont know if help you but there is the [Interval Query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-intervals-query.html).

---

<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:** [April 27, 2023, 2:09pm UTC](https://discuss.elastic.co/t/match-query-with-specific-order-of-terms/328936/3 "2023-04-27T14:09:22Z")

</div>

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