# Nested problem with geo\_distance

**URL:** <https://discuss.elastic.co/t/nested-problem-with-geo-distance/10263>\
**Category:** Elasticsearch\
**Created:** [January 8, 2013, 5:05pm UTC](https://discuss.elastic.co/t/nested-problem-with-geo-distance/10263 "2013-01-08T17:05:57Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![phoenix](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/phoenix/32/1319_2.png) [@phoenix](https://discuss.elastic.co/u/phoenix)\
**Post date:** [January 8, 2013, 5:05pm UTC](https://discuss.elastic.co/t/nested-problem-with-geo-distance/10263/1 "2013-01-08T17:05:57Z")

</div>

Hi all,  
I have a strange problem with geo\_distance filtered query.

Say i have a document like this :  
{  
model: Samsung Galaxy S III  
pvttc: 350  
location: {  
lat: 44.5688896  
lon: 6.100903  
}  
seller: {  
id: 5126  
address: {  
department: 05  
city: GAP  
country: FR  
}  
}  
}

When i query for items close to a lon/lat pair, it works this way :

{  
"query" :  
{  
"filtered" : {  
"query" : {  
"match\_all" : {}  
},  
"filter" : {  
"geo\_distance" : {  
"distance" : "5km",  
"location" : {  
"lat" : 49.00331,  
"lon" : 2.0834715  
}  
}  
}  
}  
}  
}

I get my results.

But say my doc is like this :

{  
model: Samsung Galaxy S III  
pvttc: 350  
seller: {  
id: 5126  
address: {  
department: 05  
city: GAP  
country: FR  
location: {  
lat: 44.5688896  
lon: 6.100903  
}  
}  
}  
}

(note the location is nested under seller.address.)

I can't get my results if i query this way :

{  
"query" :  
{  
"filtered" : {  
"query" : {  
"match\_all" : {}  
},  
"filter" : {  
"geo\_distance" : {  
"distance" : "5km",  
"seller.address.location" : {  
"lat" : 49.00331,  
"lon" : 2.0834715  
}  
}  
}  
}  
}  
}

No hits. Same data (except for mapping, which has been updated (index  
deleted, mapping changed, and data reindexed with the location moved to its  
nested position).  
If i query for a seller.addres.geoloc (wrong field name), i get an error,  
so it actually finds the seller.address.location field, but seems not to  
work.

Any idea ?

--

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [January 8, 2013, 11:59pm UTC](https://discuss.elastic.co/t/nested-problem-with-geo-distance/10263/2 "2013-01-08T23:59:18Z")

</div>

The distance between location in your query and location in the seller  
address is close to 600km. So, you shouldn't get this record back.

On Tuesday, January 8, 2013 12:05:57 PM UTC-5, Frederic Esnault wrote:

> Hi all,  
> I have a strange problem with geo\_distance filtered query.
> 
> Say i have a document like this :  
> {  
> model: Samsung Galaxy S III  
> pvttc: 350  
> location: {  
> lat: 44.5688896  
> lon: 6.100903  
> }  
> seller: {  
> id: 5126  
> address: {  
> department: 05  
> city: GAP  
> country: FR  
> }  
> }  
> }
> 
> When i query for items close to a lon/lat pair, it works this way :
> 
> {  
> "query" :  
> {  
> "filtered" : {  
> "query" : {  
> "match\_all" : {}  
> },  
> "filter" : {  
> "geo\_distance" : {  
> "distance" : "5km",  
> "location" : {  
> "lat" : 49.00331,  
> "lon" : 2.0834715  
> }  
> }  
> }  
> }  
> }  
> }
> 
> I get my results.
> 
> But say my doc is like this :
> 
> {  
> model: Samsung Galaxy S III  
> pvttc: 350  
> seller: {  
> id: 5126  
> address: {  
> department: 05  
> city: GAP  
> country: FR  
> location: {  
> lat: 44.5688896  
> lon: 6.100903  
> }  
> }  
> }  
> }
> 
> (note the location is nested under seller.address.)
> 
> I can't get my results if i query this way :
> 
> {  
> "query" :  
> {  
> "filtered" : {  
> "query" : {  
> "match\_all" : {}  
> },  
> "filter" : {  
> "geo\_distance" : {  
> "distance" : "5km",  
> "seller.address.location" : {  
> "lat" : 49.00331,  
> "lon" : 2.0834715  
> }  
> }  
> }  
> }  
> }  
> }
> 
> No hits. Same data (except for mapping, which has been updated (index  
> deleted, mapping changed, and data reindexed with the location moved to its  
> nested position).  
> If i query for a seller.addres.geoloc (wrong field name), i get an error,  
> so it actually finds the seller.address.location field, but seems not to  
> work.
> 
> Any idea ?

--

---

<div class="post-metadata">

**Author:** ![phoenix](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/phoenix/32/1319_2.png) [@phoenix](https://discuss.elastic.co/u/phoenix)\
**Post date:** [January 9, 2013, 9:11am UTC](https://discuss.elastic.co/t/nested-problem-with-geo-distance/10263/3 "2013-01-09T09:11:47Z")

</div>

Yes i almost added something to tell you not to take this distance into  
consideration. 🙂  
I DO have some items very close to my searched geopoint. That's why i get  
results when location is not nested.  
Sorry i should have told it was just a document structure example, and not  
the only data in my index.

On Wed, Jan 9, 2013 at 12:59 AM, Igor Motov [imotov@gmail.com](mailto:imotov@gmail.com) wrote:

> The distance between location in your query and location in the seller  
> address is close to 600km. So, you shouldn't get this record back.
> 
> On Tuesday, January 8, 2013 12:05:57 PM UTC-5, Frederic Esnault wrote:
> 
> > Hi all,  
> > I have a strange problem with geo\_distance filtered query.
> > 
> > Say i have a document like this :  
> > {  
> > model: Samsung Galaxy S III  
> > pvttc: 350  
> > location: {  
> > lat: 44.5688896  
> > lon: 6.100903  
> > }  
> > seller: {  
> > id: 5126  
> > address: {  
> > department: 05  
> > city: GAP  
> > country: FR  
> > }  
> > }  
> > }
> > 
> > When i query for items close to a lon/lat pair, it works this way :
> > 
> > {  
> > "query" :  
> > {  
> > "filtered" : {  
> > "query" : {  
> > "match\_all" : {}  
> > },  
> > "filter" : {  
> > "geo\_distance" : {  
> > "distance" : "5km",  
> > "location" : {  
> > "lat" : 49.00331,  
> > "lon" : 2.0834715  
> > }  
> > }  
> > }  
> > }  
> > }  
> > }
> > 
> > I get my results.
> > 
> > But say my doc is like this :
> > 
> > {  
> > model: Samsung Galaxy S III  
> > pvttc: 350  
> > seller: {  
> > id: 5126  
> > address: {  
> > department: 05  
> > city: GAP  
> > country: FR  
> > location: {  
> > lat: 44.5688896  
> > lon: 6.100903  
> > }  
> > }  
> > }  
> > }
> > 
> > (note the location is nested under seller.address.)
> > 
> > I can't get my results if i query this way :
> > 
> > {  
> > "query" :  
> > {  
> > "filtered" : {  
> > "query" : {  
> > "match\_all" : {}  
> > },  
> > "filter" : {  
> > "geo\_distance" : {  
> > "distance" : "5km",  
> > "seller.address.location" : {  
> > "lat" : 49.00331,  
> > "lon" : 2.0834715  
> > }  
> > }  
> > }  
> > }  
> > }  
> > }
> > 
> > No hits. Same data (except for mapping, which has been updated (index  
> > deleted, mapping changed, and data reindexed with the location moved to its  
> > nested position).  
> > If i query for a seller.addres.geoloc (wrong field name), i get an error,  
> > so it actually finds the seller.address.location field, but seems not to  
> > work.
> > 
> > Any idea ?
> 
> --

--

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [January 9, 2013, 11:29am UTC](https://discuss.elastic.co/t/nested-problem-with-geo-distance/10263/4 "2013-01-09T11:29:15Z")

</div>

If distance is correct, it works for  
me: [https://groups.google.com/d/topic/elasticsearch/9hJzp\_cAnuo/discussion · GitHub](https://gist.github.com/653bc34c693a1ef739fb)

On Wednesday, January 9, 2013 4:11:47 AM UTC-5, Frederic Esnault wrote:

> Yes i almost added something to tell you not to take this distance into  
> consideration. 🙂  
> I DO have some items very close to my searched geopoint. That's why i get  
> results when location is not nested.  
> Sorry i should have told it was just a document structure example, and not  
> the only data in my index.
> 
> On Wed, Jan 9, 2013 at 12:59 AM, Igor Motov \<[imo...@gmail.com](mailto:imo...@gmail.com)\<javascript:\>
> 
> > wrote:
> 
> > The distance between location in your query and location in the seller  
> > address is close to 600km. So, you shouldn't get this record back.
> > 
> > On Tuesday, January 8, 2013 12:05:57 PM UTC-5, Frederic Esnault wrote:
> > 
> > > Hi all,  
> > > I have a strange problem with geo\_distance filtered query.
> > > 
> > > Say i have a document like this :  
> > > {  
> > > model: Samsung Galaxy S III  
> > > pvttc: 350  
> > > location: {  
> > > lat: 44.5688896  
> > > lon: 6.100903  
> > > }  
> > > seller: {  
> > > id: 5126  
> > > address: {  
> > > department: 05  
> > > city: GAP  
> > > country: FR  
> > > }  
> > > }  
> > > }
> > > 
> > > When i query for items close to a lon/lat pair, it works this way :
> > > 
> > > {  
> > > "query" :  
> > > {  
> > > "filtered" : {  
> > > "query" : {  
> > > "match\_all" : {}  
> > > },  
> > > "filter" : {  
> > > "geo\_distance" : {  
> > > "distance" : "5km",  
> > > "location" : {  
> > > "lat" : 49.00331,  
> > > "lon" : 2.0834715  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }
> > > 
> > > I get my results.
> > > 
> > > But say my doc is like this :
> > > 
> > > {  
> > > model: Samsung Galaxy S III  
> > > pvttc: 350  
> > > seller: {  
> > > id: 5126  
> > > address: {  
> > > department: 05  
> > > city: GAP  
> > > country: FR  
> > > location: {  
> > > lat: 44.5688896  
> > > lon: 6.100903  
> > > }  
> > > }  
> > > }  
> > > }
> > > 
> > > (note the location is nested under seller.address.)
> > > 
> > > I can't get my results if i query this way :
> > > 
> > > {  
> > > "query" :  
> > > {  
> > > "filtered" : {  
> > > "query" : {  
> > > "match\_all" : {}  
> > > },  
> > > "filter" : {  
> > > "geo\_distance" : {  
> > > "distance" : "5km",  
> > > "seller.address.location" : {  
> > > "lat" : 49.00331,  
> > > "lon" : 2.0834715  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }
> > > 
> > > No hits. Same data (except for mapping, which has been updated (index  
> > > deleted, mapping changed, and data reindexed with the location moved to its  
> > > nested position).  
> > > If i query for a seller.addres.geoloc (wrong field name), i get an  
> > > error, so it actually finds the seller.address.location field, but seems  
> > > not to work.
> > > 
> > > Any idea ?
> > 
> > --

--

---

<div class="post-metadata">

**Author:** ![phoenix](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/phoenix/32/1319_2.png) [@phoenix](https://discuss.elastic.co/u/phoenix)\
**Post date:** [January 9, 2013, 3:15pm UTC](https://discuss.elastic.co/t/nested-problem-with-geo-distance/10263/5 "2013-01-09T15:15:37Z")

</div>

Damn...  
I tried also your way, it works...

The problem is in my mapping i guess. I declared seller and address as  
'nested' type field instead of object.

```
                        [...]
                    .startObject("seller")

```

- 

```
                       .field("type", "nested")*
                      .startObject("properties")
                          .startObject("seller_id")
                              .field("type", "string")
                              .field("store", "yes")
                              .field("index", "not_analyzed")
                          .endObject()
                          .startObject("address")
                             * .field("type", "nested")*
                              .startObject("properties")
                                  .startObject("department")
                                      .field("type", "integer")
                                      .field("store", "no")
                                      .field("index", "analyzed")
                                      .field("search_analyzer",

```

"items\_search\_analyzer")  
.field("index\_analyzer",  
"items\_index\_analyzer")  
.endObject()  
.startObject("city")  
.field("type", "string")  
.field("store","no")  
.field("index", "analyzed")  
.field("search\_analyzer",  
"items\_search\_analyzer")  
.field("index\_analyzer",  
"items\_index\_analyzer")  
.endObject()  
.startObject("location")  
.field("type", "geo\_point")  
.field("lat\_lon", true)  
.endObject()  
.startObject("country")  
[...]

If i replace the _nested_ type by _object_ type, it works.

```
                        [...]
                    .startObject("seller")

```

- 

```
                       .field("type", "object")*
                      [...]

```

I saw the "type", "nested" way of mapping nested objects in elasticsearch  
integration tests.

```
    client.admin().indices().prepareCreate("test")
            .addMapping("type1",

```

jsonBuilder().startObject().startObject("type1").startObject("properties")  
.startObject("nested1")  
_.field("type", "nested")_  
.endObject()  
.endObject().endObject().endObject())  
.execute().actionGet();

(Cf.  
[https://github.com/elasticsearch/elasticsearch/blob/master/src/test/java/org/elasticsearch/test/integration/nested/SimpleNestedTests.java](https://github.com/elasticsearch/elasticsearch/blob/master/src/test/java/org/elasticsearch/test/integration/nested/SimpleNestedTests.java)  
)

Is the nested type not suitable for (geoloc) search ?

On Wed, Jan 9, 2013 at 12:29 PM, Igor Motov [imotov@gmail.com](mailto:imotov@gmail.com) wrote:

> If distance is correct, it works for me:  
> [https://groups.google.com/d/topic/elasticsearch/9hJzp\_cAnuo/discussion · GitHub](https://gist.github.com/653bc34c693a1ef739fb)
> 
> On Wednesday, January 9, 2013 4:11:47 AM UTC-5, Frederic Esnault wrote:
> 
> > Yes i almost added something to tell you not to take this distance into  
> > consideration. 🙂  
> > I DO have some items very close to my searched geopoint. That's why i get  
> > results when location is not nested.  
> > Sorry i should have told it was just a document structure example, and  
> > not the only data in my index.
> > 
> > On Wed, Jan 9, 2013 at 12:59 AM, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:
> > 
> > > The distance between location in your query and location in the seller  
> > > address is close to 600km. So, you shouldn't get this record back.
> > > 
> > > On Tuesday, January 8, 2013 12:05:57 PM UTC-5, Frederic Esnault wrote:
> > > 
> > > > Hi all,  
> > > > I have a strange problem with geo\_distance filtered query.
> > > > 
> > > > Say i have a document like this :  
> > > > {  
> > > > model: Samsung Galaxy S III  
> > > > pvttc: 350  
> > > > location: {  
> > > > lat: 44.5688896  
> > > > lon: 6.100903  
> > > > }  
> > > > seller: {  
> > > > id: 5126  
> > > > address: {  
> > > > department: 05  
> > > > city: GAP  
> > > > country: FR  
> > > > }  
> > > > }  
> > > > }
> > > > 
> > > > When i query for items close to a lon/lat pair, it works this way :
> > > > 
> > > > {  
> > > > "query" :  
> > > > {  
> > > > "filtered" : {  
> > > > "query" : {  
> > > > "match\_all" : {}  
> > > > },  
> > > > "filter" : {  
> > > > "geo\_distance" : {  
> > > > "distance" : "5km",  
> > > > "location" : {  
> > > > "lat" : 49.00331,  
> > > > "lon" : 2.0834715  
> > > > }  
> > > > }  
> > > > }  
> > > > }  
> > > > }  
> > > > }
> > > > 
> > > > I get my results.
> > > > 
> > > > But say my doc is like this :
> > > > 
> > > > {  
> > > > model: Samsung Galaxy S III  
> > > > pvttc: 350  
> > > > seller: {  
> > > > id: 5126  
> > > > address: {  
> > > > department: 05  
> > > > city: GAP  
> > > > country: FR  
> > > > location: {  
> > > > lat: 44.5688896  
> > > > lon: 6.100903  
> > > > }  
> > > > }  
> > > > }  
> > > > }
> > > > 
> > > > (note the location is nested under seller.address.)
> > > > 
> > > > I can't get my results if i query this way :
> > > > 
> > > > {  
> > > > "query" :  
> > > > {  
> > > > "filtered" : {  
> > > > "query" : {  
> > > > "match\_all" : {}  
> > > > },  
> > > > "filter" : {  
> > > > "geo\_distance" : {  
> > > > "distance" : "5km",  
> > > > "seller.address.location" : {  
> > > > "lat" : 49.00331,  
> > > > "lon" : 2.0834715  
> > > > }  
> > > > }  
> > > > }  
> > > > }  
> > > > }  
> > > > }
> > > > 
> > > > No hits. Same data (except for mapping, which has been updated (index  
> > > > deleted, mapping changed, and data reindexed with the location moved to its  
> > > > nested position).  
> > > > If i query for a seller.addres.geoloc (wrong field name), i get an  
> > > > error, so it actually finds the seller.address.location field, but seems  
> > > > not to work.
> > > > 
> > > > Any idea ?
> > > 
> > > --
> > 
> > --

--

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [January 9, 2013, 3:37pm UTC](https://discuss.elastic.co/t/nested-problem-with-geo-distance/10263/6 "2013-01-09T15:37:50Z")

</div>

The nested type is perfectly suitable for geo point searches, it's just you  
need to use nested queries[http://www.elasticsearch.org/guide/reference/query-dsl/nested-query.html](http://www.elasticsearch.org/guide/reference/query-dsl/nested-query.html)to search nested objects. A more important question is, do you need these  
objects to be nested. Nested objects have certain overhead, and if you  
don't really need these objects to be nested, I would make them plain  
objects.

On Wednesday, January 9, 2013 10:15:37 AM UTC-5, Frederic Esnault wrote:

> Damn...  
> I tried also your way, it works...
> 
> The problem is in my mapping i guess. I declared seller and address as  
> 'nested' type field instead of object.
> 
> ```
> [...]
> .startObject("seller")
> 
> ```
> 
> - 
> 
> ```
> .field("type", "nested")*
> .startObject("properties")
> .startObject("seller_id")
> .field("type", "string")
> .field("store", "yes")
> .field("index", "not_analyzed")
> .endObject()
> .startObject("address")
> * .field("type", "nested")*
> .startObject("properties")
> .startObject("department")
> .field("type", "integer")
> .field("store", "no")
> .field("index", "analyzed")
> .field("search_analyzer", 
> 
> ```
> 
> "items\_search\_analyzer")  
> .field("index\_analyzer",  
> "items\_index\_analyzer")  
> .endObject()  
> .startObject("city")  
> .field("type", "string")  
> .field("store","no")  
> .field("index", "analyzed")  
> .field("search\_analyzer",  
> "items\_search\_analyzer")  
> .field("index\_analyzer",  
> "items\_index\_analyzer")  
> .endObject()  
> .startObject("location")  
> .field("type", "geo\_point")  
> .field("lat\_lon", true)  
> .endObject()  
> .startObject("country")  
> [...]
> 
> If i replace the _nested_ type by _object_ type, it works.
> 
> ```
> [...]
> .startObject("seller")
> 
> ```
> 
> - 
> 
> ```
> .field("type", "object")*
> [...]
> 
> ```
> 
> I saw the "type", "nested" way of mapping nested objects in elasticsearch  
> integration tests.
> 
> ```
> client.admin().indices().prepareCreate("test")
> .addMapping("type1", jsonBuilder().startObject().startObject("type1").startObject("properties")
> .startObject("nested1")
> *.field("type", "nested")*
> .endObject()
> .endObject().endObject().endObject())
> .execute().actionGet();
> 
> ```
> 
> (Cf.  
> [https://github.com/elasticsearch/elasticsearch/blob/master/src/test/java/org/elasticsearch/test/integration/nested/SimpleNestedTests.java](https://github.com/elasticsearch/elasticsearch/blob/master/src/test/java/org/elasticsearch/test/integration/nested/SimpleNestedTests.java) )
> 
> Is the nested type not suitable for (geoloc) search ?
> 
> On Wed, Jan 9, 2013 at 12:29 PM, Igor Motov \<[imo...@gmail.com](mailto:imo...@gmail.com)\<javascript:\>
> 
> > wrote:
> 
> > If distance is correct, it works for me:  
> > [https://groups.google.com/d/topic/elasticsearch/9hJzp\_cAnuo/discussion · GitHub](https://gist.github.com/653bc34c693a1ef739fb)
> > 
> > On Wednesday, January 9, 2013 4:11:47 AM UTC-5, Frederic Esnault wrote:
> > 
> > > Yes i almost added something to tell you not to take this distance into  
> > > consideration. 🙂  
> > > I DO have some items very close to my searched geopoint. That's why i  
> > > get results when location is not nested.  
> > > Sorry i should have told it was just a document structure example, and  
> > > not the only data in my index.
> > > 
> > > On Wed, Jan 9, 2013 at 12:59 AM, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:
> > > 
> > > > The distance between location in your query and location in the seller  
> > > > address is close to 600km. So, you shouldn't get this record back.
> > > > 
> > > > On Tuesday, January 8, 2013 12:05:57 PM UTC-5, Frederic Esnault wrote:
> > > > 
> > > > > Hi all,  
> > > > > I have a strange problem with geo\_distance filtered query.
> > > > > 
> > > > > Say i have a document like this :  
> > > > > {  
> > > > > model: Samsung Galaxy S III  
> > > > > pvttc: 350  
> > > > > location: {  
> > > > > lat: 44.5688896  
> > > > > lon: 6.100903  
> > > > > }  
> > > > > seller: {  
> > > > > id: 5126  
> > > > > address: {  
> > > > > department: 05  
> > > > > city: GAP  
> > > > > country: FR  
> > > > > }  
> > > > > }  
> > > > > }
> > > > > 
> > > > > When i query for items close to a lon/lat pair, it works this way :
> > > > > 
> > > > > {  
> > > > > "query" :  
> > > > > {  
> > > > > "filtered" : {  
> > > > > "query" : {  
> > > > > "match\_all" : {}  
> > > > > },  
> > > > > "filter" : {  
> > > > > "geo\_distance" : {  
> > > > > "distance" : "5km",  
> > > > > "location" : {  
> > > > > "lat" : 49.00331,  
> > > > > "lon" : 2.0834715  
> > > > > }  
> > > > > }  
> > > > > }  
> > > > > }  
> > > > > }  
> > > > > }
> > > > > 
> > > > > I get my results.
> > > > > 
> > > > > But say my doc is like this :
> > > > > 
> > > > > {  
> > > > > model: Samsung Galaxy S III  
> > > > > pvttc: 350  
> > > > > seller: {  
> > > > > id: 5126  
> > > > > address: {  
> > > > > department: 05  
> > > > > city: GAP  
> > > > > country: FR  
> > > > > location: {  
> > > > > lat: 44.5688896  
> > > > > lon: 6.100903  
> > > > > }  
> > > > > }  
> > > > > }  
> > > > > }
> > > > > 
> > > > > (note the location is nested under seller.address.)
> > > > > 
> > > > > I can't get my results if i query this way :
> > > > > 
> > > > > {  
> > > > > "query" :  
> > > > > {  
> > > > > "filtered" : {  
> > > > > "query" : {  
> > > > > "match\_all" : {}  
> > > > > },  
> > > > > "filter" : {  
> > > > > "geo\_distance" : {  
> > > > > "distance" : "5km",  
> > > > > "seller.address.location" : {  
> > > > > "lat" : 49.00331,  
> > > > > "lon" : 2.0834715  
> > > > > }  
> > > > > }  
> > > > > }  
> > > > > }  
> > > > > }  
> > > > > }
> > > > > 
> > > > > No hits. Same data (except for mapping, which has been updated (index  
> > > > > deleted, mapping changed, and data reindexed with the location moved to its  
> > > > > nested position).  
> > > > > If i query for a seller.addres.geoloc (wrong field name), i get an  
> > > > > error, so it actually finds the seller.address.location field, but seems  
> > > > > not to work.
> > > > > 
> > > > > Any idea ?
> > > > 
> > > > --
> > > 
> > > --

--

---

<div class="post-metadata">

**Author:** ![phoenix](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/phoenix/32/1319_2.png) [@phoenix](https://discuss.elastic.co/u/phoenix)\
**Post date:** [January 9, 2013, 3:50pm UTC](https://discuss.elastic.co/t/nested-problem-with-geo-distance/10263/7 "2013-01-09T15:50:39Z")

</div>

You're right, they don't really need to be nested, i'll make them plain.  
But for testing i made them nested, and wanted to know why my query did not  
work.  
And i'm wondering. Creating the same structure with type 'object' instead  
of 'nested' does not make them nested ? Maybe i misunderstand the 'nested'  
notion.

Could you rephrase my query to work on the nested types, so i know how to  
query this type of document structure ?

On Wed, Jan 9, 2013 at 4:37 PM, Igor Motov [imotov@gmail.com](mailto:imotov@gmail.com) wrote:

> The nested type is perfectly suitable for geo point searches, it's just  
> you need to use nested queries[http://www.elasticsearch.org/guide/reference/query-dsl/nested-query.html](http://www.elasticsearch.org/guide/reference/query-dsl/nested-query.html)to search nested objects. A more important question is, do you need these  
> objects to be nested. Nested objects have certain overhead, and if you  
> don't really need these objects to be nested, I would make them plain  
> objects.
> 
> On Wednesday, January 9, 2013 10:15:37 AM UTC-5, Frederic Esnault wrote:
> 
> > Damn...  
> > I tried also your way, it works...
> > 
> > The problem is in my mapping i guess. I declared seller and address as  
> > 'nested' type field instead of object.
> > 
> > ```
> > [...]
> > .startObject("seller")
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > .field("type", "nested")*
> > .startObject("properties")
> > **.startObject("seller_id")
> > **.field("type", "string")
> > **.field("store", "yes")
> > **.field("index", "not_analyzed")
> > **.endObject()
> > **.startObject("address")
> > ** * .field("type", "nested")*
> > **.startObject("properties")
> > **.startObject("department")
> > **.field("type", "integer")
> > **.field("store", "no")
> > **.field("index", "analyzed")
> > **.field("search_analyzer",
> > 
> > ```
> > 
> > "items\_search\_analyzer")  
> > \*\* .field("index\_analyzer",  
> > "items\_index\_analyzer")  
> > \*\* .endObject()  
> > \*\* .startObject("city")  
> > \*\* .field("type", "string")  
> > \*\* .field("store","no")  
> > \*\* .field("index", "analyzed")  
> > \*\* .field("search\_analyzer",  
> > "items\_search\_analyzer")  
> > \*\* .field("index\_analyzer",  
> > "items\_index\_analyzer")  
> > \*\* .endObject()  
> > \*\* .startObject("location")  
> > \*\* .field("type", "geo\_point")  
> > \*\* .field("lat\_lon", true)  
> > \*\* .endObject()  
> > \*\* .startObject("country")  
> > [...]
> > 
> > If i replace the _nested_ type by _object_ type, it works.
> > 
> > ```
> > [...]
> > .startObject("seller")
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > .field("type", "object")*
> > [...]
> > 
> > ```
> > 
> > I saw the "type", "nested" way of mapping nested objects in elasticsearch  
> > integration tests.
> > 
> > ```
> > client.admin().indices**().prepareCreate("test")
> > .addMapping("**type1", jsonBuilder().startObject().st**artObject("type1").startObject**("properties")
> > .start**Object("nested1")
> > *.field("type", "nested")*
> > .endOb**ject()
> > .endOb**ject().endObject().endObject()**)
> > .execute().act**ionGet();
> > 
> > ```
> > 
> > (Cf.  
> > [https://github.com/\*\*elasticsearch/elasticsearch/\*\*blob/master/src/test/java/org/\*\*elasticsearch/test/\*\*integration/nested/\*\*SimpleNestedTests.java](https://github.com/ **elasticsearch/elasticsearch/** blob/master/src/test/java/org/ **elasticsearch/test/** integration/nested/**SimpleNestedTests.java) [https://github.com/elasticsearch/elasticsearch/blob/master/src/test/java/org/elasticsearch/test/integration/nested/SimpleNestedTests.java](https://github.com/elasticsearch/elasticsearch/blob/master/src/test/java/org/elasticsearch/test/integration/nested/SimpleNestedTests.java) )
> > 
> > Is the nested type not suitable for (geoloc) search ?
> > 
> > On Wed, Jan 9, 2013 at 12:29 PM, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:
> > 
> > > If distance is correct, it works for me: [https://gist.github.com/](https://gist.github.com/)\*\*  
> > > 653bc34c693a1ef739fb [https://gist.github.com/653bc34c693a1ef739fb](https://gist.github.com/653bc34c693a1ef739fb)
> > > 
> > > On Wednesday, January 9, 2013 4:11:47 AM UTC-5, Frederic Esnault wrote:
> > > 
> > > > Yes i almost added something to tell you not to take this distance into  
> > > > consideration. 🙂  
> > > > I DO have some items very close to my searched geopoint. That's why i  
> > > > get results when location is not nested.  
> > > > Sorry i should have told it was just a document structure example, and  
> > > > not the only data in my index.
> > > > 
> > > > On Wed, Jan 9, 2013 at 12:59 AM, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:
> > > > 
> > > > > The distance between location in your query and location in the seller  
> > > > > address is close to 600km. So, you shouldn't get this record back.
> > > > > 
> > > > > On Tuesday, January 8, 2013 12:05:57 PM UTC-5, Frederic Esnault wrote:
> > > > > 
> > > > > > Hi all,  
> > > > > > I have a strange problem with geo\_distance filtered query.
> > > > > > 
> > > > > > Say i have a document like this :  
> > > > > > {  
> > > > > > model: Samsung Galaxy S III  
> > > > > > pvttc: 350  
> > > > > > location: {  
> > > > > > lat: 44.5688896  
> > > > > > lon: 6.100903  
> > > > > > }  
> > > > > > seller: {  
> > > > > > id: 5126  
> > > > > > address: {  
> > > > > > department: 05  
> > > > > > city: GAP  
> > > > > > country: FR  
> > > > > > }  
> > > > > > }  
> > > > > > }
> > > > > > 
> > > > > > When i query for items close to a lon/lat pair, it works this way :
> > > > > > 
> > > > > > {  
> > > > > > "query" :  
> > > > > > {  
> > > > > > "filtered" : {  
> > > > > > "query" : {  
> > > > > > "match\_all" : {}  
> > > > > > },  
> > > > > > "filter" : {  
> > > > > > "geo\_distance" : {  
> > > > > > "distance" : "5km",  
> > > > > > "location" : {  
> > > > > > "lat" : 49.00331,  
> > > > > > "lon" : 2.0834715  
> > > > > > }  
> > > > > > }  
> > > > > > }  
> > > > > > }  
> > > > > > }  
> > > > > > }
> > > > > > 
> > > > > > I get my results.
> > > > > > 
> > > > > > But say my doc is like this :
> > > > > > 
> > > > > > {  
> > > > > > model: Samsung Galaxy S III  
> > > > > > pvttc: 350  
> > > > > > seller: {  
> > > > > > id: 5126  
> > > > > > address: {  
> > > > > > department: 05  
> > > > > > city: GAP  
> > > > > > country: FR  
> > > > > > location: {  
> > > > > > lat: 44.5688896  
> > > > > > lon: 6.100903  
> > > > > > }  
> > > > > > }  
> > > > > > }  
> > > > > > }
> > > > > > 
> > > > > > (note the location is nested under seller.address.)
> > > > > > 
> > > > > > I can't get my results if i query this way :
> > > > > > 
> > > > > > {  
> > > > > > "query" :  
> > > > > > {  
> > > > > > "filtered" : {  
> > > > > > "query" : {  
> > > > > > "match\_all" : {}  
> > > > > > },  
> > > > > > "filter" : {  
> > > > > > "geo\_distance" : {  
> > > > > > "distance" : "5km",  
> > > > > > "seller.address.location" : {  
> > > > > > "lat" : 49.00331,  
> > > > > > "lon" : 2.0834715  
> > > > > > }  
> > > > > > }  
> > > > > > }  
> > > > > > }  
> > > > > > }  
> > > > > > }
> > > > > > 
> > > > > > No hits. Same data (except for mapping, which has been updated (index  
> > > > > > deleted, mapping changed, and data reindexed with the location moved to its  
> > > > > > nested position).  
> > > > > > If i query for a seller.addres.geoloc (wrong field name), i get an  
> > > > > > error, so it actually finds the seller.address.location field, but seems  
> > > > > > not to work.
> > > > > > 
> > > > > > Any idea ?
> > > > > 
> > > > > --
> > > > 
> > > > --
> > 
> > --

--

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [January 9, 2013, 5:10pm UTC](https://discuss.elastic.co/t/nested-problem-with-geo-distance/10263/8 "2013-01-09T17:10:39Z")

</div>

Nested[http://www.elasticsearch.org/guide/reference/mapping/nested-type.html](http://www.elasticsearch.org/guide/reference/mapping/nested-type.html)and  
Object[http://www.elasticsearch.org/guide/reference/mapping/object-type.html](http://www.elasticsearch.org/guide/reference/mapping/object-type.html)are two different types. So, if you specify "object" as a type, you will  
get non-nested object.

Here is an example of a nested query

- [https://groups.google.com/d/topic/elasticsearch/9hJzp\_cAnuo/discussion · GitHub](https://gist.github.com/653bc34c693a1ef739fb#file-geo_nested_test-sh)

On Wednesday, January 9, 2013 10:50:39 AM UTC-5, Frederic Esnault wrote:

> You're right, they don't really need to be nested, i'll make them plain.  
> But for testing i made them nested, and wanted to know why my query did not  
> work.  
> And i'm wondering. Creating the same structure with type 'object' instead  
> of 'nested' does not make them nested ? Maybe i misunderstand the 'nested'  
> notion.
> 
> Could you rephrase my query to work on the nested types, so i know how to  
> query this type of document structure ?
> 
> On Wed, Jan 9, 2013 at 4:37 PM, Igor Motov \<[imo...@gmail.com](mailto:imo...@gmail.com) \<javascript:\>
> 
> > wrote:
> 
> > The nested type is perfectly suitable for geo point searches, it's just  
> > you need to use nested queries[http://www.elasticsearch.org/guide/reference/query-dsl/nested-query.html](http://www.elasticsearch.org/guide/reference/query-dsl/nested-query.html)to search nested objects. A more important question is, do you need these  
> > objects to be nested. Nested objects have certain overhead, and if you  
> > don't really need these objects to be nested, I would make them plain  
> > objects.
> > 
> > On Wednesday, January 9, 2013 10:15:37 AM UTC-5, Frederic Esnault wrote:
> > 
> > > Damn...  
> > > I tried also your way, it works...
> > > 
> > > The problem is in my mapping i guess. I declared seller and address as  
> > > 'nested' type field instead of object.
> > > 
> > > ```
> > > [...]
> > > .startObject("seller")
> > > 
> > > ```
> > > 
> > > - 
> > > 
> > > ```
> > > .field("type", "nested")*
> > > .startObject("properties")
> > > **.startObject("seller_id")
> > > **.field("type", "string")
> > > **.field("store", "yes")
> > > **.field("index", "not_analyzed")
> > > **.endObject()
> > > **.startObject("address")
> > > ** * .field("type", "nested")*
> > > **.startObject("properties")
> > > **.startObject("department")
> > > **.field("type", "integer")
> > > **.field("store", "no")
> > > **.field("index", 
> > > 
> > > ```
> > > 
> > > "analyzed")  
> > > \*\* .field("search\_analyzer",  
> > > "items\_search\_analyzer")  
> > > \*\* .field("index\_analyzer",  
> > > "items\_index\_analyzer")  
> > > \*\* .endObject()  
> > > \*\* .startObject("city")  
> > > \*\* .field("type", "string")  
> > > \*\* .field("store","no")  
> > > \*\* .field("index",  
> > > "analyzed")  
> > > \*\* .field("search\_analyzer",  
> > > "items\_search\_analyzer")  
> > > \*\* .field("index\_analyzer",  
> > > "items\_index\_analyzer")  
> > > \*\* .endObject()  
> > > \*\* .startObject("location")  
> > > \*\* .field("type",  
> > > "geo\_point")  
> > > \*\* .field("lat\_lon", true)  
> > > \*\* .endObject()  
> > > \*\* .startObject("country")  
> > > [...]
> > > 
> > > If i replace the _nested_ type by _object_ type, it works.
> > > 
> > > ```
> > > [...]
> > > .startObject("seller")
> > > 
> > > ```
> > > 
> > > - 
> > > 
> > > ```
> > > .field("type", "object")*
> > > [...]
> > > 
> > > ```
> > > 
> > > I saw the "type", "nested" way of mapping nested objects in  
> > > elasticsearch integration tests.
> > > 
> > > ```
> > > client.admin().indices**().prepareCreate("test")
> > > 
> > > .addMapping("**type1", jsonBuilder().startObject().st**artObject("type1").startObject**("properties")
> > > 
> > > .start**Object("nested1")
> > > 
> > > *.field("type", "nested")*
> > > 
> > > .endOb**ject()
> > > 
> > > .endOb**ject().endObject().endObject()**)
> > > 
> > > .execute().act**ionGet();
> > > 
> > > ```
> > > 
> > > (Cf.  
> > > [https://github.com/\*\*elasticsearch/elasticsearch/\*\*blob/master/src/test/java/org/\*\*elasticsearch/test/\*\*integration/nested/\*\*SimpleNestedTests.java](https://github.com/ **elasticsearch/elasticsearch/** blob/master/src/test/java/org/ **elasticsearch/test/** integration/nested/**SimpleNestedTests.java) [https://github.com/elasticsearch/elasticsearch/blob/master/src/test/java/org/elasticsearch/test/integration/nested/SimpleNestedTests.java](https://github.com/elasticsearch/elasticsearch/blob/master/src/test/java/org/elasticsearch/test/integration/nested/SimpleNestedTests.java) )
> > > 
> > > Is the nested type not suitable for (geoloc) search ?
> > > 
> > > On Wed, Jan 9, 2013 at 12:29 PM, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:
> > > 
> > > > If distance is correct, it works for me: [https://gist.github.com/](https://gist.github.com/)\*\*  
> > > > 653bc34c693a1ef739fb [https://gist.github.com/653bc34c693a1ef739fb](https://gist.github.com/653bc34c693a1ef739fb)
> > > > 
> > > > On Wednesday, January 9, 2013 4:11:47 AM UTC-5, Frederic Esnault wrote:
> > > > 
> > > > > Yes i almost added something to tell you not to take this distance  
> > > > > into consideration. 🙂  
> > > > > I DO have some items very close to my searched geopoint. That's why i  
> > > > > get results when location is not nested.  
> > > > > Sorry i should have told it was just a document structure example, and  
> > > > > not the only data in my index.
> > > > > 
> > > > > On Wed, Jan 9, 2013 at 12:59 AM, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:
> > > > > 
> > > > > > The distance between location in your query and location in the  
> > > > > > seller address is close to 600km. So, you shouldn't get this record back.
> > > > > > 
> > > > > > On Tuesday, January 8, 2013 12:05:57 PM UTC-5, Frederic Esnault wrote:
> > > > > > 
> > > > > > > Hi all,  
> > > > > > > I have a strange problem with geo\_distance filtered query.
> > > > > > > 
> > > > > > > Say i have a document like this :  
> > > > > > > {  
> > > > > > > model: Samsung Galaxy S III  
> > > > > > > pvttc: 350  
> > > > > > > location: {  
> > > > > > > lat: 44.5688896  
> > > > > > > lon: 6.100903  
> > > > > > > }  
> > > > > > > seller: {  
> > > > > > > id: 5126  
> > > > > > > address: {  
> > > > > > > department: 05  
> > > > > > > city: GAP  
> > > > > > > country: FR  
> > > > > > > }  
> > > > > > > }  
> > > > > > > }
> > > > > > > 
> > > > > > > When i query for items close to a lon/lat pair, it works this way :
> > > > > > > 
> > > > > > > {  
> > > > > > > "query" :  
> > > > > > > {  
> > > > > > > "filtered" : {  
> > > > > > > "query" : {  
> > > > > > > "match\_all" : {}  
> > > > > > > },  
> > > > > > > "filter" : {  
> > > > > > > "geo\_distance" : {  
> > > > > > > "distance" : "5km",  
> > > > > > > "location" : {  
> > > > > > > "lat" : 49.00331,  
> > > > > > > "lon" : 2.0834715  
> > > > > > > }  
> > > > > > > }  
> > > > > > > }  
> > > > > > > }  
> > > > > > > }  
> > > > > > > }
> > > > > > > 
> > > > > > > I get my results.
> > > > > > > 
> > > > > > > But say my doc is like this :
> > > > > > > 
> > > > > > > {  
> > > > > > > model: Samsung Galaxy S III  
> > > > > > > pvttc: 350  
> > > > > > > seller: {  
> > > > > > > id: 5126  
> > > > > > > address: {  
> > > > > > > department: 05  
> > > > > > > city: GAP  
> > > > > > > country: FR  
> > > > > > > location: {  
> > > > > > > lat: 44.5688896  
> > > > > > > lon: 6.100903  
> > > > > > > }  
> > > > > > > }  
> > > > > > > }  
> > > > > > > }
> > > > > > > 
> > > > > > > (note the location is nested under seller.address.)
> > > > > > > 
> > > > > > > I can't get my results if i query this way :
> > > > > > > 
> > > > > > > {  
> > > > > > > "query" :  
> > > > > > > {  
> > > > > > > "filtered" : {  
> > > > > > > "query" : {  
> > > > > > > "match\_all" : {}  
> > > > > > > },  
> > > > > > > "filter" : {  
> > > > > > > "geo\_distance" : {  
> > > > > > > "distance" : "5km",  
> > > > > > > "seller.address.location" : {  
> > > > > > > "lat" : 49.00331,  
> > > > > > > "lon" : 2.0834715  
> > > > > > > }  
> > > > > > > }  
> > > > > > > }  
> > > > > > > }  
> > > > > > > }  
> > > > > > > }
> > > > > > > 
> > > > > > > No hits. Same data (except for mapping, which has been updated  
> > > > > > > (index deleted, mapping changed, and data reindexed with the location moved  
> > > > > > > to its nested position).  
> > > > > > > If i query for a seller.addres.geoloc (wrong field name), i get an  
> > > > > > > error, so it actually finds the seller.address.location field, but seems  
> > > > > > > not to work.
> > > > > > > 
> > > > > > > Any idea ?
> > > > > > 
> > > > > > --
> > > > > 
> > > > > --
> > > 
> > > --

--

---

<div class="post-metadata">

**Author:** ![phoenix](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/phoenix/32/1319_2.png) [@phoenix](https://discuss.elastic.co/u/phoenix)\
**Post date:** [January 11, 2013, 11:12am UTC](https://discuss.elastic.co/t/nested-problem-with-geo-distance/10263/9 "2013-01-11T11:12:21Z")

</div>

Thanks for the info. I'll dive into the differences more deeply later. But  
for now i understand why i didn't get my results.  
And thanks for the pointer on the nested query sample.

On Wed, Jan 9, 2013 at 6:10 PM, Igor Motov [imotov@gmail.com](mailto:imotov@gmail.com) wrote:

> Nested[http://www.elasticsearch.org/guide/reference/mapping/nested-type.html](http://www.elasticsearch.org/guide/reference/mapping/nested-type.html)and  
> Object[http://www.elasticsearch.org/guide/reference/mapping/object-type.html](http://www.elasticsearch.org/guide/reference/mapping/object-type.html)are two different types. So, if you specify "object" as a type, you will  
> get non-nested object.
> 
> Here is an example of a nested query -  
> [https://groups.google.com/d/topic/elasticsearch/9hJzp\_cAnuo/discussion · GitHub](https://gist.github.com/653bc34c693a1ef739fb#file-geo_nested_test-sh)
> 
> On Wednesday, January 9, 2013 10:50:39 AM UTC-5, Frederic Esnault wrote:
> 
> > You're right, they don't really need to be nested, i'll make them plain.  
> > But for testing i made them nested, and wanted to know why my query did not  
> > work.  
> > And i'm wondering. Creating the same structure with type 'object' instead  
> > of 'nested' does not make them nested ? Maybe i misunderstand the 'nested'  
> > notion.
> > 
> > Could you rephrase my query to work on the nested types, so i know how to  
> > query this type of document structure ?
> > 
> > On Wed, Jan 9, 2013 at 4:37 PM, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:
> > 
> > > The nested type is perfectly suitable for geo point searches, it's just  
> > > you need to use nested queries[http://www.elasticsearch.org/guide/reference/query-dsl/nested-query.html](http://www.elasticsearch.org/guide/reference/query-dsl/nested-query.html)to search nested objects. A more important question is, do you need these  
> > > objects to be nested. Nested objects have certain overhead, and if you  
> > > don't really need these objects to be nested, I would make them plain  
> > > objects.
> > > 
> > > On Wednesday, January 9, 2013 10:15:37 AM UTC-5, Frederic Esnault wrote:
> > > 
> > > > Damn...  
> > > > I tried also your way, it works...
> > > > 
> > > > The problem is in my mapping i guess. I declared seller and address as  
> > > > 'nested' type field instead of object.
> > > > 
> > > > ```
> > > > [...]
> > > > .startObject("seller")
> > > > 
> > > > ```
> > > > 
> > > > - 
> > > > 
> > > > ```
> > > > .field("type", "nested")*
> > > > .startObject("properties")
> > > > ****.startObject("seller_id")
> > > > ****.field("type", "string")
> > > > ****.field("store", "yes")
> > > > ****.field("index", "not_analyzed")
> > > > ****.endObject()
> > > > ****.startObject("address")
> > > > **** * .field("type", "nested")*
> > > > ****.startObject("properties")
> > > > ****.startObject("department")
> > > > ****.field("type",
> > > > 
> > > > ```
> > > > 
> > > > "integer")  
> > > > \*\*\*\* .field("store", "no")  
> > > > \*\*\*\* .field("index",  
> > > > "analyzed")  
> > > > \*\*\*\*  
> > > > .field("search\_analyzer", "items\_search\_analyzer")  
> > > > \*\*\*\*  
> > > > .field("index\_analyzer", "items\_index\_analyzer")  
> > > > \*\*\*\* .endObject()  
> > > > \*\*\*\* .startObject("city")  
> > > > \*\*\*\* .field("type",  
> > > > "string")  
> > > > \*\*\*\* .field("store","no")  
> > > > \*\*\*\* .field("index",  
> > > > "analyzed")  
> > > > \*\*\*\*  
> > > > .field("search\_analyzer", "items\_search\_analyzer")  
> > > > \*\*\*\*  
> > > > .field("index\_analyzer", "items\_index\_analyzer")  
> > > > \*\*\*\* .endObject()  
> > > > \*\*\*\* .startObject("location")  
> > > > \*\*\*\* .field("type",  
> > > > "geo\_point")  
> > > > \*\*\*\* .field("lat\_lon", true)  
> > > > \*\*\*\* .endObject()  
> > > > \*\*\*\* .startObject("country")  
> > > > [...]
> > > > 
> > > > If i replace the _nested_ type by _object_ type, it works.
> > > > 
> > > > ```
> > > > [...]
> > > > .startObject("seller")
> > > > 
> > > > ```
> > > > 
> > > > - 
> > > > 
> > > > ```
> > > > .field("type", "object")*
> > > > [...]
> > > > 
> > > > ```
> > > > 
> > > > I saw the "type", "nested" way of mapping nested objects in  
> > > > elasticsearch integration tests.
> > > > 
> > > > ```
> > > > client.admin().indices **** ().prepareCreate("test")
> > > > 
> > > > .addMapping(" **t** ype1", jsonBuilder().startObject().st****artObject("type1").startObject****("properties")
> > > > 
> > > > .start **** Object("nested1")
> > > > 
> > > > *.field("type", "nested")*
> > > > 
> > > > .endOb **** ject()
> > > > 
> > > > .endOb****ject().endObject().endObject()****)
> > > > 
> > > > .execute().act **** ionGet();
> > > > 
> > > > ```
> > > > 
> > > > (Cf.  
> > > > [https://github.com/\*\*elasticsear\*\*ch/elasticsearch/\*\*blob/master/\*\*src/test/java/org/\*\*elasticsearc\*\*h/test/\*\*integration/nested/\*\*Simp\*\*leNestedTests.java](https://github.com/ **elasticsear** ch/elasticsearch/ **blob/master/** src/test/java/org/ **elasticsearc** h/test/ **integration/nested/** Simp**leNestedTests.java) [https://github.com/elasticsearch/elasticsearch/blob/master/src/test/java/org/elasticsearch/test/integration/nested/SimpleNestedTests.java](https://github.com/elasticsearch/elasticsearch/blob/master/src/test/java/org/elasticsearch/test/integration/nested/SimpleNestedTests.java) )
> > > > 
> > > > Is the nested type not suitable for (geoloc) search ?
> > > > 
> > > > On Wed, Jan 9, 2013 at 12:29 PM, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:
> > > > 
> > > > > If distance is correct, it works for me: [https://gist.github.com/\*\*65](https://gist.github.com/**65)\*  
> > > > > \*3bc34c693a1ef739fb [https://gist.github.com/653bc34c693a1ef739fb](https://gist.github.com/653bc34c693a1ef739fb)
> > > > > 
> > > > > On Wednesday, January 9, 2013 4:11:47 AM UTC-5, Frederic Esnault wrote:
> > > > > 
> > > > > > Yes i almost added something to tell you not to take this distance  
> > > > > > into consideration. 🙂  
> > > > > > I DO have some items very close to my searched geopoint. That's why i  
> > > > > > get results when location is not nested.  
> > > > > > Sorry i should have told it was just a document structure example,  
> > > > > > and not the only data in my index.
> > > > > > 
> > > > > > On Wed, Jan 9, 2013 at 12:59 AM, Igor Motov [imo...@gmail.com](mailto:imo...@gmail.com) wrote:
> > > > > > 
> > > > > > > The distance between location in your query and location in the  
> > > > > > > seller address is close to 600km. So, you shouldn't get this record back.
> > > > > > > 
> > > > > > > On Tuesday, January 8, 2013 12:05:57 PM UTC-5, Frederic Esnault  
> > > > > > > wrote:
> > > > > > > 
> > > > > > > > Hi all,  
> > > > > > > > I have a strange problem with geo\_distance filtered query.
> > > > > > > > 
> > > > > > > > Say i have a document like this :  
> > > > > > > > {  
> > > > > > > > model: Samsung Galaxy S III  
> > > > > > > > pvttc: 350  
> > > > > > > > location: {  
> > > > > > > > lat: 44.5688896  
> > > > > > > > lon: 6.100903  
> > > > > > > > }  
> > > > > > > > seller: {  
> > > > > > > > id: 5126  
> > > > > > > > address: {  
> > > > > > > > department: 05  
> > > > > > > > city: GAP  
> > > > > > > > country: FR  
> > > > > > > > }  
> > > > > > > > }  
> > > > > > > > }
> > > > > > > > 
> > > > > > > > When i query for items close to a lon/lat pair, it works this way :
> > > > > > > > 
> > > > > > > > {  
> > > > > > > > "query" :  
> > > > > > > > {  
> > > > > > > > "filtered" : {  
> > > > > > > > "query" : {  
> > > > > > > > "match\_all" : {}  
> > > > > > > > },  
> > > > > > > > "filter" : {  
> > > > > > > > "geo\_distance" : {  
> > > > > > > > "distance" : "5km",  
> > > > > > > > "location" : {  
> > > > > > > > "lat" : 49.00331,  
> > > > > > > > "lon" : 2.0834715  
> > > > > > > > }  
> > > > > > > > }  
> > > > > > > > }  
> > > > > > > > }  
> > > > > > > > }  
> > > > > > > > }
> > > > > > > > 
> > > > > > > > I get my results.
> > > > > > > > 
> > > > > > > > But say my doc is like this :
> > > > > > > > 
> > > > > > > > {  
> > > > > > > > model: Samsung Galaxy S III  
> > > > > > > > pvttc: 350  
> > > > > > > > seller: {  
> > > > > > > > id: 5126  
> > > > > > > > address: {  
> > > > > > > > department: 05  
> > > > > > > > city: GAP  
> > > > > > > > country: FR  
> > > > > > > > location: {  
> > > > > > > > lat: 44.5688896  
> > > > > > > > lon: 6.100903  
> > > > > > > > }  
> > > > > > > > }  
> > > > > > > > }  
> > > > > > > > }
> > > > > > > > 
> > > > > > > > (note the location is nested under seller.address.)
> > > > > > > > 
> > > > > > > > I can't get my results if i query this way :
> > > > > > > > 
> > > > > > > > {  
> > > > > > > > "query" :  
> > > > > > > > {  
> > > > > > > > "filtered" : {  
> > > > > > > > "query" : {  
> > > > > > > > "match\_all" : {}  
> > > > > > > > },  
> > > > > > > > "filter" : {  
> > > > > > > > "geo\_distance" : {  
> > > > > > > > "distance" : "5km",  
> > > > > > > > "seller.address.location" : {  
> > > > > > > > "lat" : 49.00331,  
> > > > > > > > "lon" : 2.0834715  
> > > > > > > > }  
> > > > > > > > }  
> > > > > > > > }  
> > > > > > > > }  
> > > > > > > > }  
> > > > > > > > }
> > > > > > > > 
> > > > > > > > No hits. Same data (except for mapping, which has been updated  
> > > > > > > > (index deleted, mapping changed, and data reindexed with the location moved  
> > > > > > > > to its nested position).  
> > > > > > > > If i query for a seller.addres.geoloc (wrong field name), i get an  
> > > > > > > > error, so it actually finds the seller.address.location field, but seems  
> > > > > > > > not to work.
> > > > > > > > 
> > > > > > > > Any idea ?
> > > > > > > 
> > > > > > > --
> > > > > > 
> > > > > > --
> > > > 
> > > > --
> > 
> > --

--

---

<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:56am UTC](https://discuss.elastic.co/t/nested-problem-with-geo-distance/10263/10 "2017-07-06T02:56:52Z")

</div>


