Nested problem with geo_distance

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 ?

--

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 ?

--

Yes i almost added something to tell you not to take this distance into
consideration. :slight_smile:
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 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 ?

--

--

If distance is correct, it works for
me: https://groups.google.com/d/topic/elasticsearch/9hJzp_cAnuo/discussion · GitHub

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. :slight_smile:
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<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 ?

--

--

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
)

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

On Wed, Jan 9, 2013 at 12:29 PM, Igor Motov imotov@gmail.com wrote:

If distance is correct, it works for me:
https://groups.google.com/d/topic/elasticsearch/9hJzp_cAnuo/discussion · GitHub

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. :slight_smile:
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 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 ?

--

--

--

The nested type is perfectly suitable for geo point searches, it's just you
need to use nested querieshttp://www.elasticsearch.org/guide/reference/query-dsl/nested-query.htmlto 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 )

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

On Wed, Jan 9, 2013 at 12:29 PM, Igor Motov <imo...@gmail.com<javascript:>

wrote:

If distance is correct, it works for me:
https://groups.google.com/d/topic/elasticsearch/9hJzp_cAnuo/discussion · GitHub

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. :slight_smile:
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 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 ?

--

--

--

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 wrote:

The nested type is perfectly suitable for geo point searches, it's just
you need to use nested querieshttp://www.elasticsearch.org/guide/reference/query-dsl/nested-query.htmlto 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 )

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

On Wed, Jan 9, 2013 at 12:29 PM, Igor Motov imo...@gmail.com wrote:

If distance is correct, it works for me: 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. :slight_smile:
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 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 ?

--

--

--

--

Nestedhttp://www.elasticsearch.org/guide/reference/mapping/nested-type.htmland
Objecthttp://www.elasticsearch.org/guide/reference/mapping/object-type.htmlare 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

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 <javascript:>

wrote:

The nested type is perfectly suitable for geo point searches, it's just
you need to use nested querieshttp://www.elasticsearch.org/guide/reference/query-dsl/nested-query.htmlto 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 )

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

On Wed, Jan 9, 2013 at 12:29 PM, Igor Motov imo...@gmail.com wrote:

If distance is correct, it works for me: 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. :slight_smile:
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 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 ?

--

--

--

--

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 wrote:

Nestedhttp://www.elasticsearch.org/guide/reference/mapping/nested-type.htmland
Objecthttp://www.elasticsearch.org/guide/reference/mapping/object-type.htmlare 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

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 wrote:

The nested type is perfectly suitable for geo point searches, it's just
you need to use nested querieshttp://www.elasticsearch.org/guide/reference/query-dsl/nested-query.htmlto 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/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 wrote:

If distance is correct, it works for me: https://gist.github.com/**65*
*3bc34c693a1ef739fb 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. :slight_smile:
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 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 ?

--

--

--

--

--