# Partial phrase or exact phrase matching

**URL:** <https://discuss.elastic.co/t/partial-phrase-or-exact-phrase-matching/242320>\
**Category:** Elasticsearch\
**Created:** [July 23, 2020, 10:15am UTC](https://discuss.elastic.co/t/partial-phrase-or-exact-phrase-matching/242320 "2020-07-23T10:15:35Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![bradconor](https://avatars.discourse-cdn.com/v4/letter/b/9dc877/32.png) [@bradconor](https://discuss.elastic.co/u/bradconor)\
**Post date:** [July 23, 2020, 10:15am UTC](https://discuss.elastic.co/t/partial-phrase-or-exact-phrase-matching/242320/1 "2020-07-23T10:15:35Z")

</div>

Hi there,

I am new to elasticsearch and I want to search for a phrase.  
Suppose I query with this phrase :

`i am new to elasticsearch`

And I have some data like  
`new to elasticsearch`

I have tried with `match_phrase` but it won't return the document.

---

<div class="post-metadata">

**Author:** ![defalt](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/defalt/32/71379_2.png) [@defalt](https://discuss.elastic.co/u/defalt)\
**Post date:** [July 23, 2020, 10:50am UTC](https://discuss.elastic.co/t/partial-phrase-or-exact-phrase-matching/242320/2 "2020-07-23T10:50:00Z")

</div>

For exact matches you will need a term query [https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-query.html).

---

<div class="post-metadata">

**Author:** ![bradconor](https://avatars.discourse-cdn.com/v4/letter/b/9dc877/32.png) [@bradconor](https://discuss.elastic.co/u/bradconor)\
**Post date:** [July 23, 2020, 11:11am UTC](https://discuss.elastic.co/t/partial-phrase-or-exact-phrase-matching/242320/3 "2020-07-23T11:11:45Z")

</div>

My main issue here is that if I have `i am new to elasticsearch` as data and I query with `new to elasticsearch`, it works but not vice versa

---

<div class="post-metadata">

**Author:** ![defalt](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/defalt/32/71379_2.png) [@defalt](https://discuss.elastic.co/u/defalt)\
**Post date:** [July 23, 2020, 11:12am UTC](https://discuss.elastic.co/t/partial-phrase-or-exact-phrase-matching/242320/4 "2020-07-23T11:12:43Z")

</div>

What does your query look like? What does your mapping look like?

---

<div class="post-metadata">

**Author:** ![bradconor](https://avatars.discourse-cdn.com/v4/letter/b/9dc877/32.png) [@bradconor](https://discuss.elastic.co/u/bradconor)\
**Post date:** [July 23, 2020, 11:19am UTC](https://discuss.elastic.co/t/partial-phrase-or-exact-phrase-matching/242320/5 "2020-07-23T11:19:46Z")

</div>

I just have a simple mapping

```auto
{
  "mappings": {
      "properties": {
        "sentence": { "type": "text" }
      }
    }
}

```

And I query like this :

```auto
{
  "query": {
    "match_phrase": {
      "sentence": {
        "query": "i am new to elasticsearch"
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![defalt](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/defalt/32/71379_2.png) [@defalt](https://discuss.elastic.co/u/defalt)\
**Post date:** [July 23, 2020, 11:32am UTC](https://discuss.elastic.co/t/partial-phrase-or-exact-phrase-matching/242320/6 "2020-07-23T11:32:14Z")

</div>

Hmm, I dont see why this doesnt work.

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [July 23, 2020, 11:41am UTC](https://discuss.elastic.co/t/partial-phrase-or-exact-phrase-matching/242320/7 "2020-07-23T11:41:31Z")

</div>

The "I" part of the phrase is missing from the doc.

Generally it's advisable to combine multiple matching strategies as `should` clauses in one `bool` request.  
You can have (in order of strictness..)

1. Phrase matches
2. OR matches
3. fuzzy matches

Documents that match all of the criteria will rank highest while those that match only one clause will rank lower. Boosts on particular clauses may help.  
Avoid making the sloppier queries too sloppy or you'll create a "long tail" of low-quality results which will mess up any aggregation counts or make sorting by anything other than relevance reveal lots of low-quality matches.

---

<div class="post-metadata">

**Author:** ![bradconor](https://avatars.discourse-cdn.com/v4/letter/b/9dc877/32.png) [@bradconor](https://discuss.elastic.co/u/bradconor)\
**Post date:** [July 23, 2020, 1:02pm UTC](https://discuss.elastic.co/t/partial-phrase-or-exact-phrase-matching/242320/8 "2020-07-23T13:02:54Z")

</div>

I see your point.

However, is there any way to use `minimum_should_match` with the `match_phrase` query because I need to take account of the words order ?

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [July 23, 2020, 2:01pm UTC](https://discuss.elastic.co/t/partial-phrase-or-exact-phrase-matching/242320/9 "2020-07-23T14:01:36Z")

</div>

No - there's a "slop" setting for how far apart the words can be but currently nothing that permits dropping of a number of terms from the phrase.

---

<div class="post-metadata">

**Author:** ![bradconor](https://avatars.discourse-cdn.com/v4/letter/b/9dc877/32.png) [@bradconor](https://discuss.elastic.co/u/bradconor)\
**Post date:** [July 23, 2020, 2:53pm UTC](https://discuss.elastic.co/t/partial-phrase-or-exact-phrase-matching/242320/10 "2020-07-23T14:53:56Z")

</div>

I already tried the "slop" setting but it seems not working though.

---

<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:** [August 20, 2020, 2:54pm UTC](https://discuss.elastic.co/t/partial-phrase-or-exact-phrase-matching/242320/11 "2020-08-20T14:54:02Z")

</div>

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