# Phrase\_prefix query is not resulting the first term in the term.In the scenerio in autocomplete

**URL:** <https://discuss.elastic.co/t/phrase-prefix-query-is-not-resulting-the-first-term-in-the-term-in-the-scenerio-in-autocomplete/107901>\
**Category:** Elasticsearch\
**Created:** [November 16, 2017, 10:25am UTC](https://discuss.elastic.co/t/phrase-prefix-query-is-not-resulting-the-first-term-in-the-term-in-the-scenerio-in-autocomplete/107901 "2017-11-16T10:25:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![venkat2758](https://avatars.discourse-cdn.com/v4/letter/v/45deac/32.png) [@venkat2758](https://discuss.elastic.co/u/venkat2758)\
**Post date:** [November 16, 2017, 10:25am UTC](https://discuss.elastic.co/t/phrase-prefix-query-is-not-resulting-the-first-term-in-the-term-in-the-scenerio-in-autocomplete/107901/1 "2017-11-16T10:25:54Z")

</div>

Hi Team ,

I am facing the issue while doing autocomplete in elasticsearch.

# my Query:

GET /gensuite/itemfacetdata/\_search  
{  
"size" : 100,

```
  "query" : {
    "match_phrase_prefix": {
      "3": "doo"
    }
  },

```

"highlight" : {  
"fields" : {  
"3" : {  
"fragment\_size" : 0,  
"number\_of\_fragments" : 0  
}  
}  
}

# result:

{  
"took": 15,  
"timed\_out": false,  
"\_shards": {  
"total": 5,  
"successful": 5,  
"skipped": 0,  
"failed": 0  
},  
"hits": {  
"total": 99704,  
"max\_score": 21.841854,  
"hits": [  
{  
"\_index": "gensuite",  
"\_type": "itemfacetdata",  
"\_id": "1175344\_1\_1",  
"\_score": 21.841854,  
"\_source": {  
"3": [  
"PANEL, BOUNDER FRONT DOORSIDELUGGAGE DOO"  
],  
"7": [  
"EA"  
],  
"8": [  
"1.00"  
],  
"9": [  
"USAS"  
],  
"10": [  
"1"  
],  
"11": [  
"627498"  
],  
"13": [  
"false"  
],  
"14": [  
"627498"  
],  
"37": "1",  
"partId": 1175344,  
"languageId": 1,  
"mediaId": 0,  
"partTypeId": 1,  
"partNumber": "627498"  
},  
"highlight": {  
"3": [  
"PANEL, BOUNDER FRONT _DOORSIDELUGGAGE_ _DOO_"  
]  
}  
}  
}

My expectation is the term which starts with 'doo' should br resulted first .

I have loaded the data to the ES By bulkupdate and do not have any analyzer.

Thanks in Advance .

Regards:  
Venkatesh.

---

<div class="post-metadata">

**Author:** ![luiz.santos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/luiz.santos/32/24664_2.png) [@luiz.santos](https://discuss.elastic.co/u/luiz.santos)\
**Post date:** [November 26, 2017, 10:20pm UTC](https://discuss.elastic.co/t/phrase-prefix-query-is-not-resulting-the-first-term-in-the-term-in-the-scenerio-in-autocomplete/107901/2 "2017-11-26T22:20:05Z")

</div>

HI Venkatesh,

I think I didn't get perfectly what you are looking for. Did you expect that elasticsearch reordered the terms from your document? Elasticsearch will not change the document in the query result. It will present the documents exactly how they were indexed. But it will grant a better score to those documents where the term "doo" are more relevant.

In the highlight section you will find the matched terms surrounded by an `<em>doo</em>` so you can use it to mark the term as bold, for example.

Please, also consider using the [completion suggester](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-completion.html) to create autocomplete behaviors as they are more specialized structures for this use case.

Hope it helps!

Cheers,  
LG

---

<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:** [December 24, 2017, 10:20pm UTC](https://discuss.elastic.co/t/phrase-prefix-query-is-not-resulting-the-first-term-in-the-term-in-the-scenerio-in-autocomplete/107901/3 "2017-12-24T22:20:08Z")

</div>

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