# Unexpected match\_phrase\_prefix query result

**URL:** https://discuss.elastic.co/t/unexpected-match-phrase-prefix-query-result/81111
**Category:** Elasticsearch
**Created:** [April 4, 2017, 9:38am UTC](https://discuss.elastic.co/t/unexpected-match-phrase-prefix-query-result/81111 "2017-04-04T09:38:08Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![heni](https://avatars.discourse-cdn.com/v4/letter/h/82dd89/32.png) [@heni](https://discuss.elastic.co/u/heni)
#### Post date: [April 4, 2017, 9:38am UTC](https://discuss.elastic.co/t/unexpected-match-phrase-prefix-query-result/81111/1 "2017-04-04T09:38:08Z")

</div>

Any explanation why match\_phrase\_prefix search for "good m" failes while "good mo" search is successfull?  
The doc in my index is:  
{  
"\_index": "search\_ltv\_2017-04-02t08:40:01.000z",  
"\_type": "eng",  
"\_id": "uri:prg:pass-program-57464243~uri:scd:TV04:pass-program-57464243:05042017060000\_eng",  
"\_source": {  
"startTime": 1491372000000,  
"duration": 3600000,  
"endTime": 1491375600000,  
"channelId": "TV04",  
"title": "Good morning"  
}

The document is returned by:  
{  
"query":  
{ "bool":  
{ "should":  
[{ "match\_phrase\_prefix": { "title": "Good mo" } }]  
}  
}  
}  
But is not returned by:  
{  
"query":  
{ "bool":  
{ "should":  
[{ "match\_phrase\_prefix": { "title": "Good m" } }]  
}  
}  
}

Result is:  
{  
"took": 2,  
"timed\_out": false,  
"\_shards": {  
"total": 5,  
"successful": 5,  
"failed": 0  
},  
"hits": {  
"total": 0,  
"max\_score": null,  
"hits": [],  
}  
}

BTW, same works fine for other documents such as "Good evening" which is returned by "good e" match\_phrase\_prefix query. What can explain the failure for this specific document?

---

<div class="post-metadata">

### Author: ![jkuang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jkuang/32/72637_2.png) [@jkuang](https://discuss.elastic.co/u/jkuang)
#### Post date: [April 4, 2017, 9:39pm UTC](https://discuss.elastic.co/t/unexpected-match-phrase-prefix-query-result/81111/2 "2017-04-04T21:39:41Z")

</div>

Can you provide the full mapping? I'm not able to reproduce your issue. I'm using ES 5.3.

```auto
PUT myprefix

POST myprefix/results
{
  "message" : "Good morning"
}

GET myprefix/results/_search
{
"query": 
{ "bool": 
{ "should": 
[{ "match_phrase_prefix": { "message": "Good mo" } }] 
} 
}
}

GET myprefix/results/_search
{ 
"query": 
{ "bool": 
{ "should": 
[{ "match_phrase_prefix": { "message": "Good m" } }] 
} 
} 
}

```

Both GET queries return the same results

```auto
{
  "took": 34,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 0.51623213,
    "hits": [
      {
        "_index": "myprefix",
        "_type": "results",
        "_id": "AVs65H7hIX8nR50qxS08",
        "_score": 0.51623213,
        "_source": {
          "message": "Good morning"
        }
      }
    ]
  }
}

```

---

<div class="post-metadata">

### Author: ![heni](https://avatars.discourse-cdn.com/v4/letter/h/82dd89/32.png) [@heni](https://discuss.elastic.co/u/heni)
#### Post date: [April 6, 2017, 9:32am UTC](https://discuss.elastic.co/t/unexpected-match-phrase-prefix-query-result/81111/3 "2017-04-06T09:32:17Z")

</div>

I’m using 2.4.4, my mapping is:

```
{
    "settings":{
        "index":{
            "analysis":{
                "analyzer":{
                    "analyzer_keyword":{
                        "tokenizer":"keyword",
                        "filter":"lowercase"
                    }
                }
            }
         }
    },
    "mappings": {
        "_default_": {
            "properties": {
                "assetId": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "region": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "availability": {
                    "type": "nested",
                    "properties": {
                        "catalogId": {
                            "type": "string",
                            "index": "not_analyzed"
                        }
                    }
                },
                "contentId": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "startTime": {
                    "type": "date",
                    "index": "not_analyzed"
                },
                "title": {
                    "type": "string",
                    "copy_to": "title_and_cast",
                    "fields": {
                        "raw": {
                            "type": "string",
                            "index": "not_analyzed"
                        }
                    }
                },
                "actors": {
                    "type": "string",
                    "copy_to": "title_and_cast"
                },
                "directors": {
                    "type": "string",
                    "copy_to": "title_and_cast"
                },
                "title_and_cast": {
                    "type": "string",
                    "analyzer":"analyzer_keyword"
                }
            }
        }
    }
}
```

---

<div class="post-metadata">

### Author: ![jkuang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jkuang/32/72637_2.png) [@jkuang](https://discuss.elastic.co/u/jkuang)
#### Post date: [April 6, 2017, 9:41pm UTC](https://discuss.elastic.co/t/unexpected-match-phrase-prefix-query-result/81111/4 "2017-04-06T21:41:55Z")

</div>

Do you have another version of ES you can try this on? I still can't reproduce your problem . I'm using ES 5.X and 2.3.

---

<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: [April 8, 2017, 3:48pm UTC](https://discuss.elastic.co/t/unexpected-match-phrase-prefix-query-result/81111/5 "2017-04-08T15:48:50Z")

</div>

The search for 'good m' will expand to the first 50 (by default) 'm' words alphabetically found in the index - even if they have nothing to do with 'good' eg mad, made, map, mat etc That finds nothing.

Your search for 'good mo' might expand to something like moon, moose, morning and therefore match.

---

<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: [May 6, 2017, 4:02pm UTC](https://discuss.elastic.co/t/unexpected-match-phrase-prefix-query-result/81111/6 "2017-05-06T16:02:46Z")

</div>

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