Hello all,
I am trying to upgrade an elastic search app from 1.7.X to 2.4 version, but I am not able to reproduce the same search results on the new version.
First thing that I identify is the sort by location is not working properly. I wonder if it is related to the query itself or the sort node should be in a different way. Or it is a bug or my miss interpretation from the docs.
Structure
This is the structure of the elastic search:
The file @elastic_search_mapping:
{
"settings": {
"index": {
"analysis": {
"analyzer": {
"firm_name_analyzer": { "tokenizer": "whitespace", "filter": "lowercase" }
}
}
}
},
"mappings": {
"firms": {
"properties": {
"registered_name": { "type": "string", "analyzer": "firm_name_analyzer" },
"postcode_searchable": { "type": "boolean" },
"advisers": {
"type": "nested",
"properties": {
"location": { "type": "geo_point" },
"range_location": { "type": "geo_shape" },
"range": { "type": "integer" },
"name": { "type": "string", "index": "not_analyzed" }
}
}
}
}
}
}
Run with:
curl -XPOST http://127.0.0.1:9200/rad_development -d @elastic_search_mapping.json
Old Elastic search 1.7 query
This works great with elastic search 1.7. The sort by location worked fine out of
the filter/query terms too. Here is the query:
curl -XPOST http:localhost:9200/rad_development/firms/_search?from=0' -d '
{
"sort":[
{
"_geo_distance":{
"advisers.location":[
-0.1647512,
51.548809
],
"order":"asc",
"unit":"miles"
}
},
"registered_name"
],
"query":{
"filtered":{
"filter":{
"bool":{
"must":[
]
}
},
"query":{
"bool":{
"must":[
{
"match":{
"postcode_searchable":true
}
},
{
"nested":{
"path":"advisers",
"filter":{
"bool":{
"must":{
"geo_shape":{
"range_location":{
"relation":"intersects",
"shape":{
"type":"point",
"coordinates":[
-0.1647512,
51.548809
]
}
}
}
},
"should":{
"geo_distance":{
"distance":"750miles",
"location":[
-0.1647512,
51.548809
]
}
}
}
}
}
}
]
}
}
}
}
}'
Returns the data filtered and sorted by location as expected:
Trying to return the same result as the old elastic search version
This is my attempt to migrate the old query above to elastic search 2.4 compatible. This query returns results but not exactly the ones expcted. It appears that the sort by distance is not working or the filter is not being applied properly. Anyway this my attempt:
curl -XPOST http://localhost:9200/rad_development/firms/_search?from=0 -d '
{
"sort":[
{
"_geo_distance":{
"advisers.location":[
-0.1647512,
51.548809
],
"order":"asc",
"unit":"mi"
}
}
],
"query":{
"bool":{
"must":[
{
"match":{
"postcode_searchable":true
}
},
{
"nested":{
"path":"advisers",
"filter":{
"bool":{
"must":{
"geo_shape":{
"advisers.range_location":{
"relation":"intersects",
"shape":{
"type":"point",
"coordinates":[
-0.1647512,
51.548809
]
}
}
}
},
"should":{
"geo_distance":{
"distance":"750miles",
"advisers.location":[
-0.1647512,
51.548809
]
}
}
}
}
}
}
]
}
}
}
Anyone has some thoughts or point some direction on why the sort by location on the new version is not working at all? I followed the sort by location docs but perhaps I am missing something...
Many thanks!