Hello!
I have a list of documents that contains geoloc field which is a geo_point
type as seen in the mapping below (some fields has been stripped).
{
"schools": {
"properties": {
....
"geoloc": {
"store": "yes",
"type": "geo_point"
},
"country": {
"index": "not_analyzed",
"store": "yes",
"type": "string"
},
"username": {
"index": "not_analyzed",
"type": "string"
}
....
....
}
}
}
The default facet attached to the query is a geo_distance facet using
to/from to define range as seen below (again some range were stripped to
shorten this post).
"facets": {
"geoloc": {
"geo_distance": {
"ranges": [
….
….
{
"from": "7001",
"to": "8000"
},
{
"from": "8001",
"to": "9000"
},
{
"from": "9001",
"to": "10000"
},
{
"from": "10001",
"to": "50000"
}
],
"geoloc": {
"lat": 51.5128,
"lon": -0.0918
},
"unit": "miles"
}
}
}
The above facet query returns the following response.
"facets": {
"geoloc": {
"_type": "geo_distance",
"ranges": [
....
....
{
"from": 6001,
"to": 7000,
"min": "Infinity",
"max": "-Infinity",
"total_count": 0,
"total": 0,
"mean": "NaN"
},
{
"from": 7001,
"to": 8000,
"min": 7971.960904721318,
"max": 7971.960904721318,
"total_count": 4,
"total": 31887.843618885272,
"mean": 7971.960904721318
},
{
"from": 8001,
"to": 9000,
"min": 8127.135465210893,
"max": 8876.39022791625,
"total_count": 8,
"total": 67474.56494917188,
"mean": 8434.320618646485
},
{
"from": 9001,
"to": 10000,
"min": 9094.99960175981,
"max": 9998.014376489728,
"total_count": 1533,
"total": 14749196.606093463,
"mean": 9621.132815455618
},
{
"from": 10001,
"to": 50000,
"min": 10107.137498621609,
"max": 11991.886489810546,
"total_count": 1241,
"total": 12977180.049243744,
"mean": 10457.034689156926
}
]
}
}
Effective Range with counts
7,001 - 8,000 miles (4)
8,001 - 9,000 miles (8)
9,001 - 10,000 miles (1,531)
More than 10,000 miles (1,239)
In my application, I selected 7001 to 8000 miles with (4) expected records
within this range. The following filters are applied to the new
Request/Query:
Query Filter:
"filter": {
"and": [
{
"geo_distance_range": {
"from": "7001 mi",
"to": "8000 mi",
"geoloc": {
"lat": 51.5128,
"lon": -0.0918
}
}
}
]
}
Facet Filter (geoloc):
"facets": {
"geoloc": {
"facet_filter": {
"and": [
{
"geo_distance_range": {
"from": "7001 mi",
"to": "8000 mi",
"geoloc": {
"lat": 51.5128,
"lon": -0.0918
}
}
}
]
},
"geo_distance": {
"ranges": [
{
"from": "7001",
"to": "8000"
},
{
"from": "8001",
"to": "9000"
},
{
"from": "9001",
"to": "10000"
},
{
"from": "10001",
"to": "50000"
}
],
"geoloc": {
"lat": 51.5128,
"lon": -0.0918
},
"unit": "miles"
}
}
The Response contains the following facet values:
"facets": {
"geoloc": {
"_type": "geo_distance",
"ranges": [
…
...
{
"from": 6001,
"to": 7000,
"min": "Infinity",
"max": "-Infinity",
"total_count": 0,
"total": 0,
"mean": "NaN"
},
{
"from": 7001,
"to": 8000,
"min": 7971.960904721318,
"max": 7971.960904721318,
"total_count": 4,
"total": 31887.843618885272,
"mean": 7971.960904721318
},
{
"from": 8001,
"to": 9000,
"min": "Infinity",
"max": "-Infinity",
"total_count": 0,
"total": 0,
"mean": "NaN"
},
{
"from": 9001,
"to": 10000,
"min": "Infinity",
"max": "-Infinity",
"total_count": 0,
"total": 0,
"mean": "NaN"
},
{
"from": 10001,
"to": 50000,
"min": 10214.110601712535,
"max": 10214.110601712535,
"total_count": 4,
"total": 40856.44240685014,
"mean": 10214.110601712535
}
]
}
}
*Range with values: *
- 7001 - 8000 (4 records)
- 10001 - 50000 (4 records)
*Other observations: *
- Sending 7001 to 8000 range returns four records
- Sending 10001 to 50000 range returns greater than four records.
ElasticSearch version Used:
- 0.19.3
- 0.17.6
Has anyone experience this kind of behavior? It looks like
geo_distance_range is not working correctly for me or I maybe I am missing
something.
Thank you!
Raul