# Help me modify this query so that it can find out the matches which contain N terms in a specific order as opposed to all matches possible which contain the N terms

**URL:** <https://discuss.elastic.co/t/help-me-modify-this-query-so-that-it-can-find-out-the-matches-which-contain-n-terms-in-a-specific-order-as-opposed-to-all-matches-possible-which-contain-the-n-terms/203507>\
**Category:** Elasticsearch\
**Created:** [October 14, 2019, 6:20pm UTC](https://discuss.elastic.co/t/help-me-modify-this-query-so-that-it-can-find-out-the-matches-which-contain-n-terms-in-a-specific-order-as-opposed-to-all-matches-possible-which-contain-the-n-terms/203507 "2019-10-14T18:20:15Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![hjiop\_oop](https://avatars.discourse-cdn.com/v4/letter/h/ed8c4c/32.png) [@hjiop\_oop](https://discuss.elastic.co/u/hjiop_oop)\
**Post date:** [October 14, 2019, 8:08pm UTC](https://discuss.elastic.co/t/help-me-modify-this-query-so-that-it-can-find-out-the-matches-which-contain-n-terms-in-a-specific-order-as-opposed-to-all-matches-possible-which-contain-the-n-terms/203507/4 "2019-10-14T20:08:12Z")

</div>

Apparently, match\_phrase is a solution but according to this article this is not the case:

> [@Querystring search: Tokens are out of order](https://discuss.elastic.co/t/querystring-search-tokens-are-out-of-order/23238/5):
>
> You understanding is correct. The former will be translated into a Lucene phrase query, which uses the term doc positions to find matches. Both query terms are analyzed, but the latter will simply be a bag-of-words query, which ignores positions. Cheers, Ivan On Apr 14, 2015 10:38 PM, "Dave Reed" [infinity88@gmail.com](mailto:infinity88@gmail.com) wrote: To perhaps answer my own question, I think I understand the difference. details:"foo bar" Would search for the tokens in the same order (implied by the docs I ref…

```
body = {
    "query": {
        "multi_match" : {
            "query": "word1 word2",
            "fields": ["data"],
            "type": "phrase",
            "slop": 9999
        }
    }
}

```

Just tried this, can confirm, that it gives same results regardless of order of words considered.

---

_[View the full topic](https://discuss.elastic.co/t/help-me-modify-this-query-so-that-it-can-find-out-the-matches-which-contain-n-terms-in-a-specific-order-as-opposed-to-all-matches-possible-which-contain-the-n-terms/203507)._
