Reputation: 93
ElasticSeach is not returning the desired results when querying for iPad Mini 3 64GB AT&T
ElasticSearch highest scored result is iPad Mini 2 64GB AT&T and iPad Mini 3 64GB AT&T is 5th in the results.
Here is the mapping section for BrandAndDeviceName:
"BrandAndDeviceName": {
"type": "string",
"fields": {
"autocomplete": {
"type": "string",
"analyzer": "autocomplete"
}
}
},
And REST call
GET /devices/device/_search/
{
"query": {
"filtered": {
"query": {
"query_string": {
"query": "iPad Mini 3 64GB AT&T",
"default_field": "BrandAndDeviceName.autocomplete"
}
},
"filter": {
"and": [
{
"term": {
"Active": true
}
}
]
}
}
},
"size": 12,
"from": 0
}
This was the top result
{
"_index": "devices",
"_type": "device",
"_id": "94698082-d5cb-4f54-829e-dc62e196c894",
"_score": 9.904099,
"_source": {
"DeviceId": "94698082-d5cb-4f54-829e-dc62e196c894",
"DeviceName": "iPad Mini 2 64GB AT&T",
"Active": true,
"Brand": {
"Id": "7d04b58b-3f2d-4f63-821f-7f081d7f1bd9",
"Name": "Apple"
},
"Category": {
"CategoryId": "41d45e60-9587-4dd9-828f-5dacf02a499f",
"CategoryName": "Tablets"
},
"DeviceGroup": {
"Id": "b362318d-5c24-4dd9-a371-3261c6b38ac6",
"Name": "iPad Mini 2"
},
"BrandAndDeviceName": "Apple iPad Mini 2 64GB AT&T"
}
},
Notice that iPad Mini 2 64GB AT&T is returned with the highest score of 9.904099 and the expected document is the 5th one returned with a score of 9.483598
{
"_index": "devices",
"_type": "device",
"_id": "5dd038b7-1dea-491d-8d69-fb349970b8a2",
"_score": 9.483598,
"_source": {
"DeviceId": "5dd038b7-1dea-491d-8d69-fb349970b8a2",
"DeviceName": "iPad Mini 3 64GB AT&T",
"Active": true,
"Brand": {
"Id": "7d04b58b-3f2d-4f63-821f-7f081d7f1bd9",
"Name": "Apple"
},
"Category": {
"CategoryId": "41d45e60-9587-4dd9-828f-5dacf02a499f",
"CategoryName": "Tablets"
},
"BrandAndDeviceName": "Apple iPad Mini 3 64GB AT&T"
}
},
Why would Apple iPad Mini 2 64GB AT&T get a higher score than Apple iPad Mini 3 64GB AT&T?
Upvotes: 2
Views: 585
Reputation: 62648
Filter queries are unscored; they are simply pass/fail.
Filters are usually faster than queries because they don’t have to calculate the relevance _score for each document — the answer is just a boolean “Yes, the document matches the filter” or “No, the document does not match the filter”.
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-filtered-query.html
If you want scored results, just use a query, rather than a filter.
GET /devices/device/_search/
{
"query": {
"query_string": {
"query": "iPad Mini 3 64GB AT&T",
"default_field": "BrandAndDeviceName.autocomplete"
}
},
"filter": {
"and": [
{
"term": {
"Active": true
}
}
]
},
"size": 12,
"from": 0
}
Upvotes: 1