# Geo\_bounding\_box against nested subdocument

**URL:** https://discuss.elastic.co/t/geo-bounding-box-against-nested-subdocument/14382
**Category:** Elasticsearch
**Created:** [November 13, 2013, 1:56pm UTC](https://discuss.elastic.co/t/geo-bounding-box-against-nested-subdocument/14382 "2013-11-13T13:56:16Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![bants](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bants/32/1509_2.png) [@bants](https://discuss.elastic.co/u/bants)
#### Post date: [November 13, 2013, 1:56pm UTC](https://discuss.elastic.co/t/geo-bounding-box-against-nested-subdocument/14382/1 "2013-11-13T13:56:16Z")

</div>

Hi all,

I have data that looks something like:

{ "unique\_id" : "foo",

> "data\_type" : "bar",  
> "contents" : [

```
                 { "value" : "chris", "location" : { "lat" : 40.12, 

```

> "lon" : -71.34 }},

```
                 { "value" : "john", "location" : { "lat" : 30.15, 

```

> "lon" : -81.34 }}

```
                ] 

```

}

\*Is it possible to use a geo\_bounding\_box to search against these  
locations? \*I have seen that ES supports searching against multi-locations  
per document[http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-geo-bounding-box-filter.html#\_multi\_location\_per\_document](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-geo-bounding-box-filter.html#_multi_location_per_document) which  
should work well for this, but I can't find an example of searching against  
documents in which the locations are squirrelled away in sub-documents  
inside an array/list (as above).

I also saw this post[http://stackoverflow.com/questions/13177276/searching-term-in-subdocuments-with-elasticsearch](http://stackoverflow.com/questions/13177276/searching-term-in-subdocuments-with-elasticsearch)that suggested a wildcard could be used in the field key, which I thought  
might allow me to do a geo\_bounding\_box against \*.location or something  
similar.

I'm also aware that the fix might be to change my document structure, but  
would like to explore whether it is possible before doing that.

A big point you might pick up on - I haven't tried this for myself yet. I'm  
at the stage of working out whether Elasticsearch will do what I need it to  
do, so before I embark on writing the code I was hoping someone could help  
me out?

Thanks for the help.

--  
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, 11:22am UTC](https://discuss.elastic.co/t/geo-bounding-box-against-nested-subdocument/14382/2 "2013-11-14T11:22:32Z")

</div>

Hey,

you can simply search for the field contents.location and if anyone of the  
sub objects match, the whole document should be returned.

--Alex

On Wed, Nov 13, 2013 at 2:56 PM, bants [rich.brantingham@me.com](mailto:rich.brantingham@me.com) wrote:

> Hi all,
> 
> I have data that looks something like:
> 
> { "unique\_id" : "foo",
> 
> > "data\_type" : "bar",  
> > "contents" : [
> 
> ```
> { "value" : "chris", "location" : { "lat" : 40.12,
> 
> ```
> 
> > "lon" : -71.34 }},
> 
> ```
> { "value" : "john", "location" : { "lat" : 30.15,
> 
> ```
> 
> > "lon" : -81.34 }}
> 
> ```
> ]
> 
> ```
> 
> }
> 
> \*Is it possible to use a geo\_bounding\_box to search against these  
> locations? \*I have seen that ES supports searching against multi-locations  
> per document[http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-geo-bounding-box-filter.html#\_multi\_location\_per\_document](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-geo-bounding-box-filter.html#_multi_location_per_document) which  
> should work well for this, but I can't find an example of searching against  
> documents in which the locations are squirrelled away in sub-documents  
> inside an array/list (as above).
> 
> I also saw this post[http://stackoverflow.com/questions/13177276/searching-term-in-subdocuments-with-elasticsearch](http://stackoverflow.com/questions/13177276/searching-term-in-subdocuments-with-elasticsearch)that suggested a wildcard could be used in the field key, which I thought  
> might allow me to do a geo\_bounding\_box against \*.location or something  
> similar.
> 
> I'm also aware that the fix might be to change my document structure, but  
> would like to explore whether it is possible before doing that.
> 
> A big point you might pick up on - I haven't tried this for myself yet.  
> I'm at the stage of working out whether Elasticsearch will do what I need  
> it to do, so before I embark on writing the code I was hoping someone could  
> help me out?
> 
> Thanks for the help.
> 
> --  
> 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: ![bants](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bants/32/1509_2.png) [@bants](https://discuss.elastic.co/u/bants)
#### Post date: [November 14, 2013, 4:38pm UTC](https://discuss.elastic.co/t/geo-bounding-box-against-nested-subdocument/14382/3 "2013-11-14T16:38:30Z")

</div>

Great - I was hoping it'd be that simple!

Thanks Alex.

On 14 Nov 2013, at 11:22, Alexander Reelsen [alr@spinscale.de](mailto:alr@spinscale.de) wrote:

> Hey,
> 
> you can simply search for the field contents.location and if anyone of the sub objects match, the whole document should be returned.
> 
> --Alex
> 
> On Wed, Nov 13, 2013 at 2:56 PM, bants [rich.brantingham@me.com](mailto:rich.brantingham@me.com) wrote:  
> Hi all,
> 
> I have data that looks something like:
> 
> { "unique\_id" : "foo",  
> "data\_type" : "bar",  
> "contents" : [  
> { "value" : "chris", "location" : { "lat" : 40.12, "lon" : -71.34 }},  
> { "value" : "john", "location" : { "lat" : 30.15, "lon" : -81.34 }}  
> ]  
> }
> 
> Is it possible to use a geo\_bounding\_box to search against these locations? I have seen that ES supports searching against multi-locations per document which should work well for this, but I can't find an example of searching against documents in which the locations are squirrelled away in sub-documents inside an array/list (as above).
> 
> I also saw this post that suggested a wildcard could be used in the field key, which I thought might allow me to do a geo\_bounding\_box against \*.location or something similar.
> 
> I'm also aware that the fix might be to change my document structure, but would like to explore whether it is possible before doing that.
> 
> A big point you might pick up on - I haven't tried this for myself yet. I'm at the stage of working out whether Elasticsearch will do what I need it to do, so before I embark on writing the code I was hoping someone could help me out?
> 
> Thanks for the help.
> 
> --  
> 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 a topic in the Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit [https://groups.google.com/d/topic/elasticsearch/Vig9S1n8NL0/unsubscribe](https://groups.google.com/d/topic/elasticsearch/Vig9S1n8NL0/unsubscribe).  
> To unsubscribe from this group and all its topics, 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:06am UTC](https://discuss.elastic.co/t/geo-bounding-box-against-nested-subdocument/14382/4 "2017-07-06T02:06:58Z")

</div>


