# How to apply multiple geo\_distance filters to match any of multiple locations?

**URL:** <https://discuss.elastic.co/t/how-to-apply-multiple-geo-distance-filters-to-match-any-of-multiple-locations/6947>\
**Category:** Elasticsearch\
**Created:** [March 8, 2012, 3:27pm UTC](https://discuss.elastic.co/t/how-to-apply-multiple-geo-distance-filters-to-match-any-of-multiple-locations/6947 "2012-03-08T15:27:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jim\_2](https://avatars.discourse-cdn.com/v4/letter/j/50afbb/32.png) [@Jim\_2](https://discuss.elastic.co/u/Jim_2)\
**Post date:** [March 8, 2012, 3:27pm UTC](https://discuss.elastic.co/t/how-to-apply-multiple-geo-distance-filters-to-match-any-of-multiple-locations/6947/1 "2012-03-08T15:27:08Z")

</div>

I've indexed a document like below:

curl -XPUT '[http://localhost:9200/people/person/1](http://localhost:9200/people/person/1)' -d'  
{  
"locations": [  
{  
"location": "51.0587013,-2.9499066",  
"id": 1  
},  
{  
"location": "51.38596454,-2.36162306118",  
"id": 2  
}  
]  
}'

mapped the 'location' field to geo\_point with:

curl -XPUT '[http://localhost:9200/people/person/\_mapping](http://localhost:9200/people/person/_mapping)?  
ignore\_conflicts=true' -d'  
{  
"person":{  
"properties": {  
"locations": {  
"properties": {  
"location": {  
"type": "geo\_point"  
}  
}  
}  
}  
}  
}'

I want to search so I can supply several geo\_points and receive  
results which have (at least) one location near any of the points I  
supply.

I've tried several things, none of which work, for example:

curl -XGET '[http://localhost:9200/people/person/\_search](http://localhost:9200/people/person/_search)' -d'  
{  
"query": {  
"filtered": {  
"filter": {  
"not": {  
"ids": {  
"values": [  
2  
]  
}  
},  
"geo\_distance": {  
"distance": "500mi",  
"locations.location":  
["51.38596452,-2.36162306116", "51.0587015,-2.9499065"]  
}  
}  
}  
}  
}'

I just get an exception like:

nested: QueryParsingException[[people] [\_na] filter malformed, no  
field after start\_object

How can I do this?

Thanks,  
Jim

---

<div class="post-metadata">

**Author:** ![Eric\_Jain](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eric_jain/32/834_2.png) [@Eric\_Jain](https://discuss.elastic.co/u/Eric_Jain)\
**Post date:** [March 9, 2012, 7:46pm UTC](https://discuss.elastic.co/t/how-to-apply-multiple-geo-distance-filters-to-match-any-of-multiple-locations/6947/2 "2012-03-09T19:46:33Z")

</div>

On Mar 8, 7:27 am, Jim [beanb...@googlemail.com](mailto:beanb...@googlemail.com) wrote:

> I want to search so I can supply several geo\_points and receive  
> results which have (at least) one location near any of the points I  
> supply.

I don't know if the geo\_distance filter supports searches for more  
than one geo\_point at a time. But you could combine multiple filters  
using a bool 'should' filter.

Also, to handle multiple geo\_points per document, you may need to  
index geohashes instead of lat and long.

---

<div class="post-metadata">

**Author:** ![egaumer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/egaumer/32/2365_2.png) [@egaumer](https://discuss.elastic.co/u/egaumer)\
**Post date:** [March 9, 2012, 8:58pm UTC](https://discuss.elastic.co/t/how-to-apply-multiple-geo-distance-filters-to-match-any-of-multiple-locations/6947/3 "2012-03-09T20:58:43Z")

</div>

You haven't specified a proper nested mapping. Have a look here -

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

-Eric

On Thursday, March 8, 2012 10:27:08 AM UTC-5, Jim wrote:

> I've indexed a document like below:
> 
> curl -XPUT '[http://localhost:9200/people/person/1](http://localhost:9200/people/person/1)' -d'  
> {  
> "locations": [  
> {  
> "location": "51.0587013,-2.9499066",  
> "id": 1  
> },  
> {  
> "location": "51.38596454,-2.36162306118",  
> "id": 2  
> }  
> ]  
> }'
> 
> mapped the 'location' field to geo\_point with:
> 
> curl -XPUT '[http://localhost:9200/people/person/\_mapping](http://localhost:9200/people/person/_mapping)?  
> ignore\_conflicts=true[http://localhost:9200/people/person/\_mapping?ignore\_conflicts=true](http://localhost:9200/people/person/_mapping?ignore_conflicts=true)'  
> -d'  
> {  
> "person":{  
> "properties": {  
> "locations": {  
> "properties": {  
> "location": {  
> "type": "geo\_point"  
> }  
> }  
> }  
> }  
> }  
> }'
> 
> I want to search so I can supply several geo\_points and receive  
> results which have (at least) one location near any of the points I  
> supply.
> 
> I've tried several things, none of which work, for example:
> 
> curl -XGET '[http://localhost:9200/people/person/\_search](http://localhost:9200/people/person/_search)' -d'  
> {  
> "query": {  
> "filtered": {  
> "filter": {  
> "not": {  
> "ids": {  
> "values": [  
> 2  
> ]  
> }  
> },  
> "geo\_distance": {  
> "distance": "500mi",  
> "locations.location":  
> ["51.38596452,-2.36162306116", "51.0587015,-2.9499065"]  
> }  
> }  
> }  
> }  
> }'
> 
> I just get an exception like:
> 
> nested: QueryParsingException[[people] [\_na] filter malformed, no  
> field after start\_object
> 
> How can I do this?
> 
> Thanks,  
> Jim

---

<div class="post-metadata">

**Author:** ![Jim\_2](https://avatars.discourse-cdn.com/v4/letter/j/50afbb/32.png) [@Jim\_2](https://discuss.elastic.co/u/Jim_2)\
**Post date:** [March 14, 2012, 2:33pm UTC](https://discuss.elastic.co/t/how-to-apply-multiple-geo-distance-filters-to-match-any-of-multiple-locations/6947/4 "2012-03-14T14:33:07Z")

</div>

Thanks, I didn't understand nesting, but I get it now.

On Mar 9, 8:58 pm, egaumer [egau...@gmail.com](mailto:egau...@gmail.com) wrote:

> You haven't specified a proper nested mapping. Have a look here -[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/nested-type.html)
> 
> -Eric
> 
> On Thursday, March 8, 2012 10:27:08 AM UTC-5, Jim wrote:
> 
> > I've indexed a document like below:
> 
> > curl -XPUT '[http://localhost:9200/people/person/1'-d'](http://localhost:9200/people/person/1'-d')  
> > {  
> > "locations": [  
> > {  
> > "location": "51.0587013,-2.9499066",  
> > "id": 1  
> > },  
> > {  
> > "location": "51.38596454,-2.36162306118",  
> > "id": 2  
> > }  
> > ]  
> > }'
> 
> > mapped the 'location' field to geo\_point with:
> 
> > curl -XPUT '[http://localhost:9200/people/person/\_mapping](http://localhost:9200/people/person/_mapping)?  
> > ignore\_conflicts=true[http://localhost:9200/people/person/\_mapping?ignore\_conflicts=true](http://localhost:9200/people/person/_mapping?ignore_conflicts=true)'  
> > -d'  
> > {  
> > "person":{  
> > "properties": {  
> > "locations": {  
> > "properties": {  
> > "location": {  
> > "type": "geo\_point"  
> > }  
> > }  
> > }  
> > }  
> > }  
> > }'
> 
> > I want to search so I can supply several geo\_points and receive  
> > results which have (at least) one location near any of the points I  
> > supply.
> 
> > I've tried several things, none of which work, for example:
> 
> > curl -XGET '[http://localhost:9200/people/person/\_search'-d'](http://localhost:9200/people/person/_search'-d')  
> > {  
> > "query": {  
> > "filtered": {  
> > "filter": {  
> > "not": {  
> > "ids": {  
> > "values": [  
> > 2  
> > ]  
> > }  
> > },  
> > "geo\_distance": {  
> > "distance": "500mi",  
> > "locations.location":  
> > ["51.38596452,-2.36162306116", "51.0587015,-2.9499065"]  
> > }  
> > }  
> > }  
> > }  
> > }'
> 
> > I just get an exception like:
> 
> > nested: QueryParsingException[[people] [\_na] filter malformed, no  
> > field after start\_object
> 
> > How can I do this?
> 
> > Thanks,  
> > Jim

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 3:36am UTC](https://discuss.elastic.co/t/how-to-apply-multiple-geo-distance-filters-to-match-any-of-multiple-locations/6947/5 "2017-07-06T03:36:08Z")

</div>


