# Split phrase to search

**URL:** https://discuss.elastic.co/t/split-phrase-to-search/130797
**Category:** Elasticsearch
**Created:** [May 7, 2018, 8:33am UTC](https://discuss.elastic.co/t/split-phrase-to-search/130797 "2018-05-07T08:33:02Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Michal\_Pietrasz](https://avatars.discourse-cdn.com/v4/letter/m/a88e57/32.png) [@Michal\_Pietrasz](https://discuss.elastic.co/u/Michal_Pietrasz)
#### Post date: [May 7, 2018, 8:33am UTC](https://discuss.elastic.co/t/split-phrase-to-search/130797/1 "2018-05-07T08:33:02Z")

</div>

Hello,

I need to do search mechanism when customer type "My custom phrase" in search then I need to search by:  
"My custom phrase"  
"My"  
"custom"  
"phrase"

and in same hierarchic result should be shown.

Should I use custom engine and manually split this sentence and create multiple where or there is a build in mechanism for that ?

---

<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: [May 7, 2018, 3:26pm UTC](https://discuss.elastic.co/t/split-phrase-to-search/130797/2 "2018-05-07T15:26:13Z")

</div>

You could use a `bool` query that combines a query for the entire phrase (using the `match_phrase` query), combined with a query for the individual terms (using a `match` query). The idea is that documents that contain the exact phrase will get a higher score, because they will match on both clauses.

The query cwould look something like this:

```auto
GET _search
{
  "query": {
    "bool": {
      "must": {
        "match": {
          "content": "My custom phrase"
        }
      },
      "should": {
        "match_phrase": {
          "content": "My custom phrase"
        }
      }
    }
  }
}

```

---

<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: [June 4, 2018, 3:26pm UTC](https://discuss.elastic.co/t/split-phrase-to-search/130797/3 "2018-06-04T15:26:32Z")

</div>

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