# Match\_phrase\_prefix and scores

**URL:** <https://discuss.elastic.co/t/match-phrase-prefix-and-scores/20216>\
**Category:** Elasticsearch\
**Created:** [October 13, 2014, 12:56pm UTC](https://discuss.elastic.co/t/match-phrase-prefix-and-scores/20216 "2014-10-13T12:56:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mehmet\_Cem\_Gunturkun](https://avatars.discourse-cdn.com/v4/letter/m/8491ac/32.png) [@Mehmet\_Cem\_Gunturkun](https://discuss.elastic.co/u/Mehmet_Cem_Gunturkun)\
**Post date:** [October 13, 2014, 12:56pm UTC](https://discuss.elastic.co/t/match-phrase-prefix-and-scores/20216/1 "2014-10-13T12:56:34Z")

</div>

Hi,  
I have been working on elasticsearch and I couldn't figure it out something  
about prefix search.I am trying to create a music search engine. However,  
on prefix search I have some troubles.  
Let me give some info about my index and mappings:

{  
"testindex": {  
"mappings": {  
"track": {  
"dynamic": "true",  
"numeric\_detection": true,  
"properties": {  
"album": {  
"type": "string",  
"analyzer": "music\_field"  
},  
"artist": {  
"type": "string",  
"analyzer": "music\_field"  
},  
"id": {  
"type": "string"  
},  
"title": {  
"type": "string",  
"analyzer": "music\_field"  
}  
}  
}  
}  
}  
}

Settings and main analzyers are:

{  
"testindex": {  
"settings": {  
"index": {  
"uuid": "uHDWlHxpQ22itmOcnJpi9g",  
"analysis": {  
"char\_filter": {  
"xfactor": {  
"type": "mapping",  
"mappings": [  
"-=\>"  
]  
},  
"kesha": {  
"pattern": "^([^$]+)$([^$]+)$",  
"type": "pattern\_replace",  
"replacement": "$1s$2"  
},  
"pink": {  
"pattern": "^([^$]+)!([^$]+)$",  
"type": "pattern\_replace",  
"replacement": "$1i$2"  
},  
"sharp": {  
"pattern": "^([^$]+)#([^$]+)$",  
"type": "pattern\_replace",  
"replacement": "$1h$2"  
}  
},  
"analyzer": {  
"music\_field": {  
"type": "custom",  
"char\_filter": [  
"kesha",  
"sharp",  
"pink",  
"xfactor"  
],  
"filter": [  
"asciifolding"  
],  
"tokenizer": "lowercase"  
}  
}  
},  
"number\_of\_replicas": "1",  
"number\_of\_shards": "5",  
"version": {  
"created": "1030099"  
}  
}  
}  
}  
}

After this initialization, I have 7 songs into index such as:

{  
"took": 3,  
"timed\_out": false,  
"\_shards": {  
"total": 5,  
"successful": 5,  
"failed": 0  
},  
"hits": {  
"total": 7,  
"max\_score": 1,  
"hits": [  
{  
"\_index": "testindex",  
"\_type": "track",  
"\_id": "4",  
"\_score": 1,  
"\_source": {  
"title": "Funhouse",  
"artist": "Pink",  
"album": "",  
"id": "4"  
}  
},  
{  
"\_index": "testindex",  
"\_type": "track",  
"\_id": "5",  
"\_score": 1,  
"\_source": {  
"title": "Chica Chica",  
"artist": "Pinka",  
"album": "",  
"id": "5"  
}  
},  
{  
"\_index": "testindex",  
"\_type": "track",  
"\_id": "1",  
"\_score": 1,  
"\_source": {  
"title": "Comfortably Numb",  
"artist": "Pink Floyd",  
"album": "",  
"id": "1"  
}  
},  
{  
"\_index": "testindex",  
"\_type": "track",  
"\_id": "6",  
"\_score": 1,  
"\_source": {  
"title": "Fever Dream",  
"artist": "Mr Pink",  
"album": "",  
"id": "6"  
}  
},  
{  
"\_index": "testindex",  
"\_type": "track",  
"\_id": "2",  
"\_score": 1,  
"\_source": {  
"title": "Brain Damage",  
"artist": "Pink Floyd",  
"album": "",  
"id": "2"  
}  
},  
{  
"\_index": "testindex",  
"\_type": "track",  
"\_id": "7",  
"\_score": 1,  
"\_source": {  
"title": "Another Bullshit Song",  
"artist": "Pinkafree",  
"album": "",  
"id": "7"  
}  
},  
{  
"\_index": "testindex",  
"\_type": "track",  
"\_id": "3",  
"\_score": 1,  
"\_source": {  
"title": "The Gnome",  
"artist": "Pink Floyd",  
"album": "",  
"id": "3"  
}  
}  
]  
}  
}

After that I create a query to search tracks of which artists name  
startsWith "Pink".

localhost:9200/testindex/track/\_search?pretty=true&search\_type=dfs\_query\_then\_fetch

{  
"query": {  
"match\_phrase\_prefix": {  
"artist": {  
"query": "pink"  
}  
}  
}  
}

I am expecting that Funhouse should be first one and with highest score in  
the list. However result of the search is like that:

{  
"took" : 4,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 7,  
"max\_score" : 2.3862944,  
"hits" : [ {  
"\_index" : "testindex",  
"\_type" : "track",  
"\_id" : "5",  
"\_score" : 2.3862944,  
"\_source":{"title":"Chica Chica","artist":"Pinka","album":"","id":"5"}  
}, {  
"\_index" : "testindex",  
"\_type" : "track",  
"\_id" : "7",  
"\_score" : 2.1554716,  
"\_source":{"title":"Another Bullshit  
Song","artist":"Pinkafree","album":"","id":"7"}  
}, {  
"\_index" : "testindex",  
"\_type" : "track",  
"\_id" : "4",  
"\_score" : 1.1335315,  
"\_source":{"title":"Funhouse","artist":"Pink","album":"","id":"4"}  
}, {  
"\_index" : "testindex",  
"\_type" : "track",  
"\_id" : "1",  
"\_score" : 0.7084572,  
"\_source":{"title":"Comfortably Numb","artist":"Pink  
Floyd","album":"","id":"1"}  
}, {  
"\_index" : "testindex",  
"\_type" : "track",  
"\_id" : "6",  
"\_score" : 0.7084572,  
"\_source":{"title":"Fever Dream","artist":"Mr  
Pink","album":"","id":"6"}  
}, {  
"\_index" : "testindex",  
"\_type" : "track",  
"\_id" : "3",  
"\_score" : 0.7084572,  
"\_source":{"title":"The Gnome","artist":"Pink  
Floyd","album":"","id":"3"}  
}, {  
"\_index" : "testindex",  
"\_type" : "track",  
"\_id" : "2",  
"\_score" : 0.3039775,  
"\_source":{"title":"Brain Damage","artist":"Pink  
Floyd","album":"","id":"2"}  
} ]  
}  
}

I tried regex, prefix and wildcard search. However; I culdn't find a wat  
for this problem.  
What is the ideal way to do it?

Mehmet -

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/35a2d6c0-f9a1-4770-8336-84592b434ae6%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/35a2d6c0-f9a1-4770-8336-84592b434ae6%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 12:56am UTC](https://discuss.elastic.co/t/match-phrase-prefix-and-scores/20216/2 "2017-07-06T00:56:34Z")

</div>


