# Query for geo\_bounding\_box in nested documents

**URL:** https://discuss.elastic.co/t/query-for-geo-bounding-box-in-nested-documents/14270
**Category:** Elasticsearch
**Created:** [November 5, 2013, 4:27pm UTC](https://discuss.elastic.co/t/query-for-geo-bounding-box-in-nested-documents/14270 "2013-11-05T16:27:29Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Raymond\_Pendergraph](https://avatars.discourse-cdn.com/v4/letter/r/4491bb/32.png) [@Raymond\_Pendergraph](https://discuss.elastic.co/u/Raymond_Pendergraph)
#### Post date: [November 5, 2013, 4:27pm UTC](https://discuss.elastic.co/t/query-for-geo-bounding-box-in-nested-documents/14270/1 "2013-11-05T16:27:29Z")

</div>

I am having an issue figuring out how to represent a geo\_bounding\_box query  
for a geo\_point field which is located in a nested document. It seems to be  
having an issue finding the field in the nested document. I tried leaving  
out the nested clause (just using document\_b.location in the  
geo\_bounding\_box) too but that did not seem to work either. Here is a  
simplified test case of what I am trying to do:

curl -XDELETE localhost:9200/geo\_test  
echo "Map"  
curl -XPUT localhost:9200/geo\_test -d '{  
"mappings": {  
"document\_a": {  
"properties": {  
"name": {"type": "string"},  
"document\_b": {  
"type": "nested",  
"properties": {  
"location": {  
"type": "geo\_point",  
"lat\_lon": "true"  
}  
}  
}  
}  
}  
}  
}'  
echo  
echo "Insert"  
curl -XPUT localhost:9200/geo\_test/document\_a/2 -d '{  
"id": 2,  
"name": "MyTest",  
"document\_b": {  
"location":{  
"lat": 32.9,  
"lon": 69.25  
}  
}  
}'  
echo  
echo "Refresh"  
curl -XPOST localhost:9200/geo\_test/\_refresh  
echo  
echo "Query"  
curl -XPOST "localhost:9200/geo\_test/geo\_test/\_search?pretty=true" -d '{  
"query": {  
"filtered": {  
"query": {  
"match\_all": {}  
},  
"filter": {  
"nested": {  
"path": "document\_b",  
"query": {  
"filtered":{  
"query": {"match\_all": {}},  
"filter": {  
"geo\_bounding\_box" : {  
"location" : {  
"top\_left" : {  
"lat" : 32.9,  
"lon" : 69.25  
},  
"bottom\_right" : {  
"lat" : 33.0,  
"lon" : 69.5  
}  
}  
}  
}  
}  
}  
}  
}  
}

```
  }

```

}'  
echo

The error that I am getting is  
nested: QueryParsingException[[geo\_test] failed to find geo\_point field  
[location]]

Any help is greatly appreciated.

Ray

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [November 14, 2013, 9:56am UTC](https://discuss.elastic.co/t/query-for-geo-bounding-box-in-nested-documents/14270/2 "2013-11-14T09:56:02Z")

</div>

Hey,

couple of corrections for your query

curl -XPOST "localhost:9200/geo\_test/document\_a/\_search?pretty=true" -d '{  
"query": {  
"filtered": {  
"query": {  
"match\_all": {}  
},  
"filter": {  
"nested": {  
"path": "document\_b",  
"filter": {  
"geo\_bounding\_box" : {  
"document\_b.location" : {  
"top\_left" : { "lat" : 33.0, "lon" : 69.24 },  
"bottom\_right" : { "lat" : 32.8, "lon" : 69.5 }  
}  
}  
}  
}  
}  
}  
}  
}'

Couple of minor corrections I did:

- Using a nested filter instead of a query
- Your search in your mail searched only for type geo\_test, but you needed  
to search for type document\_a
- your bounding boxes were not correct, it would never have matched (not  
kidding, but I have a small post it at my monitor which kindly shows a neat  
little earth where the lat/long ranges are running at, because I screw it  
up daily 🙂
- Even if you are inside of a nested filter, you still have to specify the  
full path in the filter (document\_b.location instead of location)

Hope this helps!

--Alex

--Alex

On Tue, Nov 5, 2013 at 5:27 PM, Raymond Pendergraph \<  
[raypendergraph@gmail.com](mailto:raypendergraph@gmail.com)\> wrote:

> I am having an issue figuring out how to represent a geo\_bounding\_box  
> query for a geo\_point field which is located in a nested document. It seems  
> to be having an issue finding the field in the nested document. I tried  
> leaving out the nested clause (just using document\_b.location in the  
> geo\_bounding\_box) too but that did not seem to work either. Here is a  
> simplified test case of what I am trying to do:
> 
> curl -XDELETE localhost:9200/geo\_test  
> echo "Map"  
> curl -XPUT localhost:9200/geo\_test -d '{  
> "mappings": {  
> "document\_a": {  
> "properties": {  
> "name": {"type": "string"},  
> "document\_b": {  
> "type": "nested",  
> "properties": {  
> "location": {  
> "type": "geo\_point",  
> "lat\_lon": "true"  
> }  
> }  
> }  
> }  
> }  
> }  
> }'  
> echo  
> echo "Insert"  
> curl -XPUT localhost:9200/geo\_test/document\_a/2 -d '{  
> "id": 2,  
> "name": "MyTest",  
> "document\_b": {  
> "location":{  
> "lat": 32.9,  
> "lon": 69.25  
> }  
> }  
> }'  
> echo  
> echo "Refresh"  
> curl -XPOST localhost:9200/geo\_test/\_refresh  
> echo  
> echo "Query"  
> curl -XPOST "localhost:9200/geo\_test/geo\_test/\_search?pretty=true" -d '{  
> "query": {  
> "filtered": {  
> "query": {  
> "match\_all": {}  
> },  
> "filter": {  
> "nested": {  
> "path": "document\_b",  
> "query": {  
> "filtered":{  
> "query": {"match\_all": {}},  
> "filter": {  
> "geo\_bounding\_box" : {  
> "location" : {  
> "top\_left" : {  
> "lat" : 32.9,  
> "lon" : 69.25  
> },  
> "bottom\_right" : {  
> "lat" : 33.0,  
> "lon" : 69.5  
> }  
> }  
> }  
> }  
> }  
> }  
> }  
> }  
> }
> 
> ```
> }
> 
> ```
> 
> }'  
> echo
> 
> The error that I am getting is  
> nested: QueryParsingException[[geo\_test] failed to find geo\_point field  
> [location]]
> 
> Any help is greatly appreciated.
> 
> Ray
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:07am UTC](https://discuss.elastic.co/t/query-for-geo-bounding-box-in-nested-documents/14270/3 "2017-07-06T02:07:11Z")

</div>


