# How to get result that contains every word in the query

**URL:** <https://discuss.elastic.co/t/how-to-get-result-that-contains-every-word-in-the-query/200628>\
**Category:** Elasticsearch\
**Created:** [September 23, 2019, 6:39am UTC](https://discuss.elastic.co/t/how-to-get-result-that-contains-every-word-in-the-query/200628 "2019-09-23T06:39:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![May](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@May](https://discuss.elastic.co/u/May)\
**Post date:** [September 23, 2019, 6:39am UTC](https://discuss.elastic.co/t/how-to-get-result-that-contains-every-word-in-the-query/200628/1 "2019-09-23T06:39:52Z")

</div>

Hi there, I would like have elasticsearch return only the docs that contain every word in the query. For example, if the user queries "wooden table", docs with "...wooden table ....." and "table .... with wooden...." will be returned but not docs that only contain "wooden" or "table". The number of words in the query is undefined so having multiple AND in query might not be ideal. I read about min\_score [https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-body.html#request-body-search-min-score](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-body.html#request-body-search-min-score), but I am not sure how min\_score is defined or works. It does not seem to be cosine similarity score, as still get result if min\_score is set over 1.

Also, how can I return docs that contains the exact ordered words in the query. If "wooden table" is queries, how can I return docs that only contains "...wooden table...." , but not "wooden....table..." or "table wooden" or anything else.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![abdon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdon/32/9195_2.png) [@abdon](https://discuss.elastic.co/u/abdon)\
**Post date:** [September 23, 2019, 9:57am UTC](https://discuss.elastic.co/t/how-to-get-result-that-contains-every-word-in-the-query/200628/2 "2019-09-23T09:57:38Z")

</div>

I'm not sure why AND would not be the solution here. You can pass in [the AND operator to a `match` query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html) and it will only return documents that match all your search terms:

```auto
GET my_index/_search
{
  "query": {
    "match": {
      "my_field": {
        "query": "wooden table",
        "operator": "and"
      }
    }
  }
}

```

If you only need a certain number of search terms to match, you can use [the `minimum_should_match` parameter](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-minimum-should-match.html). This parameter accepts a specific number, or a percentage. For example:

```auto
GET my_index/_search
{
  "query": {
    "match": {
      "my_field": {
        "query": "beautiful wooden table",
        "minimum_should_match": "80%"
      }
    }
  }
}

```

To match the exact phrase "wooden table" you can use [the `match_phrase` query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query-phrase.html):

```auto
GET my_index/_search
{
  "query": {
    "match_phrase": {
      "my_field": {
        "query": "wooden table"
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![May](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@May](https://discuss.elastic.co/u/May)\
**Post date:** [September 23, 2019, 11:10am UTC](https://discuss.elastic.co/t/how-to-get-result-that-contains-every-word-in-the-query/200628/3 "2019-09-23T11:10:50Z")

</div>

Thank you so much!

---

<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:** [October 21, 2019, 11:11am UTC](https://discuss.elastic.co/t/how-to-get-result-that-contains-every-word-in-the-query/200628/4 "2019-10-21T11:11:00Z")

</div>

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