Not getting exact match first in the elastic search

I am newbie to elastic 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

What are the results then?

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",
"count" : "39991"
}
},
{
"_index" : "index_likes_test",
"_type" : "type_likes_test",
"_id" : "900",
"_score" : 9.050074,
"_source" : {
"name" : "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",
"count" : "60538"
}
},
{
"_index" : "index_likes_test",
"_type" : "type_likes_test",
"_id" : "936",
"_score" : 8.998916,
"_source" : {
"name" : "cricket.com.au",
"count" : "80629"
}
}
]

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

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