# Match query with only 2 word search in search query

**URL:** <https://discuss.elastic.co/t/match-query-with-only-2-word-search-in-search-query/365526>\
**Category:** Elasticsearch\
**Created:** [August 26, 2024, 6:14am UTC](https://discuss.elastic.co/t/match-query-with-only-2-word-search-in-search-query/365526 "2024-08-26T06:14:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mohan\_T](https://avatars.discourse-cdn.com/v4/letter/m/34f0e0/32.png) [@Mohan\_T](https://discuss.elastic.co/u/Mohan_T)\
**Post date:** [August 26, 2024, 6:14am UTC](https://discuss.elastic.co/t/match-query-with-only-2-word-search-in-search-query/365526/1 "2024-08-26T06:14:33Z")

</div>

**Document 1:**

```auto
{
    "id": 1,
    "title": "marble flooring"
}

```

**Document 2:**

```auto
{
    "id": 2,
    "title": "flooring marble"
}

```

**Document 3:**

```auto
{
    "id": 3,
    "title": "italian marble flooring"
}

```

Existing query which am using

Query:

```auto
{
    "track_total_hits": true,
    "_source": [
        "title"
    ],
    "query": {
        "bool": {
            "should": [
               
                {
                    "match_phrase": {
                        "title.standard": {
                            "query": "marble floor",
                            "boost": 1
                        }
                    }
                }
            ],
            "minimum_should_match": "1"
        }
    }
}

```

but this above query returning all 3 documents, but I need only document 1 & document 2, guide me with the same

---

<div class="post-metadata">

**Author:** ![Musab\_Dogan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/musab_dogan/32/70691_2.png) [@Musab\_Dogan](https://discuss.elastic.co/u/Musab_Dogan)\
**Post date:** [August 26, 2024, 7:03am UTC](https://discuss.elastic.co/t/match-query-with-only-2-word-search-in-search-query/365526/2 "2024-08-26T07:03:37Z")

</div>

As far as I understand, you want to restrict the search to only documents where the field contains exactly two words, like `“marble flooring”`. Unfortunately, there isn’t a direct way to enforce this restriction within a `multi_match` or `match_phrase` query.

To check if the field contains exactly two words:

1. You can use a regular expression in the Painless script.
2. You can calculate the length of the field value during indexing.
