# Not getting exact match first in the elastic search

**URL:** <https://discuss.elastic.co/t/not-getting-exact-match-first-in-the-elastic-search/106269>\
**Category:** Elasticsearch\
**Created:** [November 3, 2017, 5:29am UTC](https://discuss.elastic.co/t/not-getting-exact-match-first-in-the-elastic-search/106269 "2017-11-03T05:29:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pavani](https://avatars.discourse-cdn.com/v4/letter/p/e9a140/32.png) [@pavani](https://discuss.elastic.co/u/pavani)\
**Post date:** [November 3, 2017, 5:29am UTC](https://discuss.elastic.co/t/not-getting-exact-match-first-in-the-elastic-search/106269/1 "2017-11-03T05:29:24Z")

</div>

I am newbie to elastic [search.So](http://search.So) i have a scenario like

i have a values like...  
cricket, cricketab, cricketbcd, cricketcd, crazy, my fav game is cricket, cricket king, cricbuzzz, cricket is universal game, anu likes cricket

So when i search with 'cricket'.The result should be like

```
cricket
cricketab
cricketbcd
cricketcd
cricket king
cricket is universal game
anu likes cricket
my fav game is cricket

And when i search with cr.The result should be like

crazy
cricbuzz
cricket
cricketab
cricketbcd
cricketcd
cricket king
cricket is universal game
anu likes cricket
my fav game is cricket

```

So i created index like

curl -XPUT 'x.x.x.x:9200/index\_like?pretty' -H 'Content-Type: application/json' -d'  
{  
"settings": {  
"analysis": {  
"filter": {  
"autocomplete\_filter": {  
"type": "edge\_ngram",  
"min\_gram": 1,  
"max\_gram": 100  
}  
},  
"analyzer": {  
"autocomplete": {  
"type": "custom",  
"tokenizer": "whitespace",  
"filter": [  
"lowercase",  
"autocomplete\_filter"  
]  
}  
}  
}  
},  
"mappings": {  
"type\_like": {  
"properties": {  
"name": {  
"type": "text",  
"fields": {  
"keyword": {  
"type": "text",  
"analyzer": "keyword"  
}  
}  
},  
"count": {  
"type": "integer"  
}  
}  
}  
}  
}  
'  
and i queried like

curl -XGET 'x.x.x.x:9200/index\_likes\_test/\_search?pretty' -H 'Content-Type: application/json' -d'  
{  
"query": {  
"bool": {  
"should": [  
{  
"term": {  
"name.keyword": {  
"value": "cricket"  
}  
}  
},  
{  
"match\_phrase": {  
"name": {  
"query" : "cricket"  
}  
}  
},  
{  
"match": {  
"name": {  
"query": "cricket"  
}  
}  
},  
{  
"match\_phrase\_prefix": {  
"name": {  
"query" : "cricket"  
}  
}  
}  
]  
}  
}  
}  
'

So i am getting exact match first.but i didn't get the result as like above  
I hope u understand my scenario.There should be exact match first in the result if exact match exists.Followed by alphabetical sorting values..  
Thank u

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [November 3, 2017, 5:41am UTC](https://discuss.elastic.co/t/not-getting-exact-match-first-in-the-elastic-search/106269/2 "2017-11-03T05:41:39Z")

</div>

> [@pavani](#):
>
> So i am getting exact match first.but i didn't get the result as like above

What are the results then?

---

<div class="post-metadata">

**Author:** ![pavani](https://avatars.discourse-cdn.com/v4/letter/p/e9a140/32.png) [@pavani](https://discuss.elastic.co/u/pavani)\
**Post date:** [November 3, 2017, 5:46am UTC](https://discuss.elastic.co/t/not-getting-exact-match-first-in-the-elastic-search/106269/3 "2017-11-03T05:46:37Z")

</div>

when i search with cric

"hits" : [  
{  
"\_index" : "index\_likes\_test",  
"\_type" : "type\_likes\_test",  
"\_id" : "890",  
"\_score" : 9.070774,  
"\_source" : {  
"name" : "crickettoday",  
"count" : "61704"  
}  
},  
{  
"\_index" : "index\_likes\_test",  
"\_type" : "type\_likes\_test",  
"\_id" : "4241",  
"\_score" : 9.056194,  
"\_source" : {  
"name" : "cricketnmore",  
"count" : "11278"  
}  
},  
{  
"\_index" : "index\_likes\_test",  
"\_type" : "type\_likes\_test",  
"\_id" : "24290",  
"\_score" : 9.056194,  
"\_source" : {  
"name" : "cricketpost24",  
"count" : "15025"  
}  
},  
{  
"\_index" : "index\_likes\_test",  
"\_type" : "type\_likes\_test",  
"\_id" : "975",  
"\_score" : 9.056194,  
"\_source" : {  
"name" : "cricbuzz",  
"count" : "166207"  
}  
},  
{  
"\_index" : "index\_likes\_test",  
"\_type" : "type\_likes\_test",  
"\_id" : "8152",  
"\_score" : 9.050074,  
"\_source" : {  
"name" : "cricketwallah",  
"count" : "37534"  
}  
},  
{  
"\_index" : "index\_likes\_test",  
"\_type" : "type\_likes\_test",  
"\_id" : "38954",  
"\_score" : 9.050074,  
"\_source" : {  
"name" : "[cricspirit.com](http://cricspirit.com)",  
"count" : "39991"  
}  
},  
{  
"\_index" : "index\_likes\_test",  
"\_type" : "type\_likes\_test",  
"\_id" : "900",  
"\_score" : 9.050074,  
"\_source" : {  
"name" : "[cricketcountry.com](http://cricketcountry.com)",  
"count" : "37656"  
}  
},  
{  
"\_index" : "index\_likes\_test",  
"\_type" : "type\_likes\_test",  
"\_id" : "29266426",  
"\_score" : 8.998916,  
"\_source" : {  
"name" : "cricketupdates",  
"count" : "21176"  
}  
},  
{  
"\_index" : "index\_likes\_test",  
"\_type" : "type\_likes\_test",  
"\_id" : "3862",  
"\_score" : 8.998916,  
"\_source" : {  
"name" : "[cricketnext.com](http://cricketnext.com)",  
"count" : "60538"  
}  
},  
{  
"\_index" : "index\_likes\_test",  
"\_type" : "type\_likes\_test",  
"\_id" : "936",  
"\_score" : 8.998916,  
"\_source" : {  
"name" : "[cricket.com.au](http://cricket.com.au)",  
"count" : "80629"  
}  
}  
]

here cricbuzz should be the first result. but i am getting crickettoday as the top one.

---

<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 1, 2017, 5:58am UTC](https://discuss.elastic.co/t/not-getting-exact-match-first-in-the-elastic-search/106269/4 "2017-12-01T05:58:18Z")

</div>

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