# Existing document not being found by match\_phrase\_prefix

**URL:** <https://discuss.elastic.co/t/existing-document-not-being-found-by-match-phrase-prefix/28941>\
**Category:** Elasticsearch\
**Created:** [September 9, 2015, 3:35pm UTC](https://discuss.elastic.co/t/existing-document-not-being-found-by-match-phrase-prefix/28941 "2015-09-09T15:35:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abid\_Hussain](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@Abid\_Hussain](https://discuss.elastic.co/u/Abid_Hussain)\
**Post date:** [September 9, 2015, 3:35pm UTC](https://discuss.elastic.co/t/existing-document-not-being-found-by-match-phrase-prefix/28941/1 "2015-09-09T15:35:40Z")

</div>

Hi all,

I've encountered some unexpected search behaviour. We have an index of documents with fields `last_name`, `first_name`.

There is a document with `first_name` _Peter_ and `last_name` _Westphal_. When running the following search:

```
{
    "query": {
        "bool": {
            "must": [
               {
                   "match_phrase_prefix": {
                      "last_name": "west"
                   }
               },
               {
                   "match_phrase_prefix": {
                      "first_name": "peter"
                   }
               }
            ]
        }
    }
}

```

nothing is found. When changing the `last_name` query from _west_ to _westp_, the customer is found.

We're using elasticsearch 1.4.2. Both fields are of type `string` no specific language analyzer is being used. Can it be that _west_ is somehow being considered as expletive word?

Using `explain: true` in query doesn't give any information. Are there any analyzation queries available to unterstand search behaviour?

Regards,

Abid

---

<div class="post-metadata">

**Author:** ![Abid\_Hussain](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@Abid\_Hussain](https://discuss.elastic.co/u/Abid_Hussain)\
**Post date:** [September 10, 2015, 8:11am UTC](https://discuss.elastic.co/t/existing-document-not-being-found-by-match-phrase-prefix/28941/2 "2015-09-10T08:11:21Z")

</div>

Encountered similar behaviour with document `first_name` _Raimund_ and `last_name` _Hartmann_.

Running the following search

```
{
    "query": {
        "bool": {
            "must": [
               {
                   "match_phrase_prefix": {
                      "last_name": "h"
                   }
               },
               {
                   "match_phrase_prefix": {
                      "first_name": "raimund"
                   }
               }
            ]
        }
    }
}

```

finds nothing. When `last_name` query term is replaced from _h_ to _hart_, the document is being found.

Any ideas...?

---

<div class="post-metadata">

**Author:** ![javanna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javanna/32/4698_2.png) [@javanna](https://discuss.elastic.co/u/javanna)\
**Post date:** [September 10, 2015, 4:41pm UTC](https://discuss.elastic.co/t/existing-document-not-being-found-by-match-phrase-prefix/28941/3 "2015-09-10T16:41:19Z")

</div>

Hello,  
do you maybe have a lot of other documents with last\_name starting with "west" but first\_name that doesn't start with "peter"? Have you tried playing around with the max\_expansions option. Default is 50, meaning that if Westphal is after the first 50 terms that start with west in the inverted index, you don't get that document back. That might explain why adding the "p" makes it match.

---

<div class="post-metadata">

**Author:** ![Abid\_Hussain](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@Abid\_Hussain](https://discuss.elastic.co/u/Abid_Hussain)\
**Post date:** [September 11, 2015, 7:19am UTC](https://discuss.elastic.co/t/existing-document-not-being-found-by-match-phrase-prefix/28941/4 "2015-09-11T07:19:03Z")

</div>

Thanks for clarification, increasing max\_expansions did it.

So it seems I'm not able to determine if a search returns nothing because no document matched or  
because too many matched.

---

<div class="post-metadata">

**Author:** ![Abid\_Hussain](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@Abid\_Hussain](https://discuss.elastic.co/u/Abid_Hussain)\
**Post date:** [September 11, 2015, 8:14am UTC](https://discuss.elastic.co/t/existing-document-not-being-found-by-match-phrase-prefix/28941/5 "2015-09-11T08:14:55Z")

</div>

I now set max\_expansions to 100. Still not all matching documents are being found when using `last_name : "west"`.

As far as I unterstand, max\_expansions in combination with match\_phrase\_prefix determines the maximum number of existing distinct fields matching the prefix.

What bothers me is that there are 36 distinct last\_name fields beginning with _west_. So I would expect that even the assumed `max_expansions` default of 50 must be enough in a match\_phrase\_prefix query and setting it to 100 must be far enough.

---

<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:** [July 5, 2017, 11:50pm UTC](https://discuss.elastic.co/t/existing-document-not-being-found-by-match-phrase-prefix/28941/6 "2017-07-05T23:50:52Z")

</div>


