Reputation: 167
Looking for a bit now to see if this is possible.
I have documents in es that have a two geopoints in their mapping.
I'm looking to create a query that I can find all documents within x miles of originGeo and y miles of destinationGeo.
I'm currently trying this a couple different ways like this:
This isn't quite what I want as it uses the same distance per geopoint. But, it also seems to only return documents pertaining to the destinationGeo.
{
"query": {
"filtered": {
"filter": {
"bool": {
"must": [],
"must_not": [{
"term": {
"system": "boo"
}
}]
}
},
"query": {
"filtered": {
"filter": {
"geo_distance": {
"distance": "1mi",
"originGeo": {
"lat": 33.9962144,
"lon": -118.46887759999998
},
"destinationGeo": {
"lat": 34.0348144,
"lon": -117.58480250000002
}
}
}
}
}
}
}
}
This results in a parse error: filter malformed, no field after start_object
{
"query": {
"filtered": {
"filter": {
"bool": {
"must": [],
"must_not": [{
"term": {
"system": "boo"
}
}]
},
"geo_distance": {
"distance": "1mi",
"originGeo": {
"lat": 33.9962144,
"lon": -118.46887759999998
},
"destinationGeo": {
"lat": 34.0348144,
"lon": -117.58480250000002
}
}
}
}
}
}
Any help is much appreciated as always!
Upvotes: 1
Views: 767
Reputation: 217564
The following query for ES 2.x and later should do what you need
{
"query": {
"bool": {
"filter": [
{
"geo_distance": {
"distance": "1mi",
"originGeo": {
"lat": 33.9962144,
"lon": -118.46887759999998
}
}
},
{
"geo_distance": {
"distance": "1mi",
"destinationGeo": {
"lat": 34.0348144,
"lon": -117.58480250000002
}
}
}
],
"must_not": [
{
"term": {
"system": "boo"
}
}
]
}
}
}
If you're running on ES 1.x, then you can use this one:
{
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{
"geo_distance": {
"distance": "1mi",
"originGeo": {
"lat": 33.9962144,
"lon": -118.46887759999998
}
}
},
{
"geo_distance": {
"distance": "1mi",
"destinationGeo": {
"lat": 34.0348144,
"lon": -117.58480250000002
}
}
}
],
"must_not": [
{
"term": {
"system": "boo"
}
}
]
}
}
}
}
}
Upvotes: 1