hi,
I'm implementing an autocomplete using text_phrase_prefix, but 'exact'
matches score lower than substring matches, so the most relevant results
don't appear first and in some cases are not in the first page fo results
(I'd like to avoid returning too many results and sorting at the client).
For example:
index:
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0
},
"mappings": {
"place": {
"dynamic": false,
"type": "object",
"properties": {
...snip...
"name": {
"type": "string",
"analyzer": "standard",
"store": "yes",
"term_vector": "with_positions_offsets"
}
...snip...
}
query:
{
"query": {
"text_phrase_prefix": {
"name": "London"
}
}
}
As you can see below, "Londonthorpe" has a score of 3.9, whereas "London"
is 1.05 (I'm wondering why the score is 1.05 and not 1, since it is a
perfect match?).
Is there a way to order results by closest match, so that the shortest
complete match is returned first - if not with text_phrase_prefix, then
perhaps a custom forward edgengram filter?
thanks for any pointers,
here are the results of the above query:
{
"took": 0,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 34,
"max_score": 3.9374971,
"hits": [
{
"_index": "places",
"_type": "place",
"_id": "82Cxx5olSR29vIa0tnQB6w",
"_score": 3.9374971,
"_source": {
"name": "Londonthorpe",
"admin2": "Lincolnshire",
"country": "GBR",
"location": "v1mth1htztws",
"rank": 3
},
"_grouped": false
},
{
"_index": "places",
"_type": "place",
"_id": "0lY8WlnxT1yvCysgCHL0NA",
"_score": 3.4017,
"_source": {
"name": "Londonderry",
"admin2": "North Yorkshire",
"country": "GBR",
"location": "v1wsdygy0zz7",
"rank": 3
},
"_grouped": false
},
{
"_index": "places",
"_type": "place",
"_id": "JS2laACxQimS7A740qNMcA",
"_score": 3.4017,
"_source": {
"name": "Londonderry",
"admin2": "Sandwell",
"country": "GBR",
"location": "v1m6d631w63y",
"rank": 3
},
"_grouped": false
},
{
"_index": "places",
"_type": "place",
"_id": "20IzrjRWSYSYaHMD24TxWg",
"_score": 1.0555032,
"_source": {
"name": "London",
"admin2": "City of London",
"country": "GBR",
"location": "v1hth63636dy",
"rank": 1
},
"_grouped": false
},
{
"_index": "places",
"_type": "place",
"_id": "WGd0GQSGS_e6Y14QoU0zCw",
"_score": 0.65968955,
"_source": {
"name": "Little London",
"admin2": "Bradford",
"country": "GBR",
"location": "v1w637h6gzw6",
"rank": 3
},
"_grouped": false
},
{
"_index": "places",
"_type": "place",
"_id": "JVEMN2DdRZqHEVCyJynoWg",
"_score": 0.65968955,
"_source": {
"name": "Little London",
"admin2": "Powys",
"country": "GBR",
"location": "v1m6d631w63y",
"rank": 3
},
"_grouped": false
},
{
"_index": "places",
"_type": "place",
"_id": "j5uNub82RRqqr03EefpmtA",
"_score": 0.65968955,
"_source": {
"name": "Little London",
"admin2": "Shropshire",
"country": "GBR",
"location": "v1m6d631w63y",
"rank": 3
},
"_grouped": false
},
{
"_index": "places",
"_type": "place",
"_id": "6oXW6HiyQjakxShTcKhpWg",
"_score": 0.65968955,
"_source": {
"name": "Little London",
"admin2": "Worcestershire",
"country": "GBR",
"location": "v1m1wygzz03t",
"rank": 3
},
"_grouped": false
},
{
"_index": "places",
"_type": "place",
"_id": "7UOGKwu5RXGyGaLcVkAIAQ",
"_score": 0.65968955,
"_source": {
"name": "Little London",
"admin2": "Gloucestershire",
"country": "GBR",
"location": "v1hygzh00sd1",
"rank": 3
},
"_grouped": false
},
{
"_index": "places",
"_type": "place",
"_id": "tnVYn2j2Q-6B6LBWi57g0w",
"_score": 0.65968955,
"_source": {
"name": "Little London",
"admin2": "Oxfordshire",
"country": "GBR",
"location": "v1hy07wy36d0",
"rank": 3
},
"_grouped": false
}
]
}
}