Term facet on geo_point field

Is there a way to store a geo_point but get the "lat,long" instead of
geohash when faceting?

curl -XPOST localhost:9200/test -d '{
"settings" : {
"number_of_shards" : 1
},
"mappings" : {
"type1" : {
"_source" : { "enabled" : false },
"properties" : {
"message" : { "type" : "string", "index" : "analyzed" },
"latlon":{"type":"geo_point",
"geohash":true,
"lat_lon":true,
"geohash_precision":4
}
}
}
}
}'

curl -XPUT 'localhost:9200/test/type1/1' -d '
{
"message" : "something blue",
"latlon" : "-23.53,-46.62"
}
'
curl -XPUT 'localhost:9200/test/type1/2' -d '
{
"message" : "something green",
"latlon" : "40.71,-74.01"
}
'
curl -XPOST 'localhost:9200/_refresh'
curl -XPOST 'localhost:9200/test/_search?pretty=true' -d '
{
"query" : {
"term" : { "message" : "something" }
},
"facets" : {
"geo" : {
"terms" : { "field" : "latlon" }
}
}
}

returns
"facets" : {
"geo" : {
"_type" : "terms",
"missing" : 0,
"total" : 2,
"other" : 0,
"terms" : [ {
"term" : "dr5reg58fn01",
"count" : 1
}, {
"term" : "6gyf5hkrg606",
"count" : 1
} ]
}
}

--

If I understand correctly, you want ES to facet on geohash, but return the
latlon instead of the hash itself?

I don't think the geo_point can do this on its own, since, the lat and lon
information is not stored in the document, so faceting on geohash cannot
retrieve the latlong information. lat and lon information is stored in the
index, but in separate fields, so faceting would need to look at both
fields (perhaps thats possible with scripting).

My guess is your better of either:

  • Storing latlon in a separate field an faceting off of that.
  • Converting the geohash to latlon on the client side. Should be simple
    enough, no?

Disclaimer - I'm pretty new to ES :slight_smile:

Cheers,
Anil

On Thursday, December 6, 2012 8:12:22 AM UTC-8, Telvis Calhoun Jr. wrote:

Is there a way to store a geo_point but get the "lat,long" instead of
geohash when faceting?

curl -XPOST localhost:9200/test -d '{
"settings" : {
"number_of_shards" : 1
},
"mappings" : {
"type1" : {
"_source" : { "enabled" : false },
"properties" : {
"message" : { "type" : "string", "index" : "analyzed" },
"latlon":{"type":"geo_point",
"geohash":true,
"lat_lon":true,
"geohash_precision":4
}
}
}
}
}'

curl -XPUT 'localhost:9200/test/type1/1' -d '
{
"message" : "something blue",
"latlon" : "-23.53,-46.62"
}
'
curl -XPUT 'localhost:9200/test/type1/2' -d '
{
"message" : "something green",
"latlon" : "40.71,-74.01"
}
'
curl -XPOST 'localhost:9200/_refresh'
curl -XPOST 'localhost:9200/test/_search?pretty=true' -d '
{
"query" : {
"term" : { "message" : "something" }
},
"facets" : {
"geo" : {
"terms" : { "field" : "latlon" }
}
}
}

returns
"facets" : {
"geo" : {
"_type" : "terms",
"missing" : 0,
"total" : 2,
"other" : 0,
"terms" : [ {
"term" : "dr5reg58fn01",
"count" : 1
}, {
"term" : "6gyf5hkrg606",
"count" : 1
} ]
}
}

--

Indeed. I can store in a separate field using a multi_field. However, I
encounter a problem when I put the multi_field in a nested document. I have
a nested document called "depart". When I attempt a geo-boundary filter on
the geo multi_field as 'depart.latlong_geo', it fails with "failed to find
geo_point field [depart.latlon_geo]];". But when I try the same
geo-boundary query with "depart.latlon.latlon_geo", everything works fine.
Odd.

I'm using 0.20.0.Beta1. A gist with the working and failed queries is
at: https://gist.github.com/4227384

Thank you for your help.

On Thursday, December 6, 2012 1:25:31 PM UTC-5, Anil Rhemtulla wrote:

If I understand correctly, you want ES to facet on geohash, but return the
latlon instead of the hash itself?

I don't think the geo_point can do this on its own, since, the lat and lon
information is not stored in the document, so faceting on geohash cannot
retrieve the latlong information. lat and lon information is stored in the
index, but in separate fields, so faceting would need to look at both
fields (perhaps thats possible with scripting).

My guess is your better of either:

  • Storing latlon in a separate field an faceting off of that.
  • Converting the geohash to latlon on the client side. Should be simple
    enough, no?

Disclaimer - I'm pretty new to ES :slight_smile:

Cheers,
Anil

On Thursday, December 6, 2012 8:12:22 AM UTC-8, Telvis Calhoun Jr. wrote:

Is there a way to store a geo_point but get the "lat,long" instead of
geohash when faceting?

curl -XPOST localhost:9200/test -d '{
"settings" : {
"number_of_shards" : 1
},
"mappings" : {
"type1" : {
"_source" : { "enabled" : false },
"properties" : {
"message" : { "type" : "string", "index" : "analyzed" },
"latlon":{"type":"geo_point",
"geohash":true,
"lat_lon":true,
"geohash_precision":4
}
}
}
}
}'

curl -XPUT 'localhost:9200/test/type1/1' -d '
{
"message" : "something blue",
"latlon" : "-23.53,-46.62"
}
'
curl -XPUT 'localhost:9200/test/type1/2' -d '
{
"message" : "something green",
"latlon" : "40.71,-74.01"
}
'
curl -XPOST 'localhost:9200/_refresh'
curl -XPOST 'localhost:9200/test/_search?pretty=true' -d '
{
"query" : {
"term" : { "message" : "something" }
},
"facets" : {
"geo" : {
"terms" : { "field" : "latlon" }
}
}
}

returns
"facets" : {
"geo" : {
"_type" : "terms",
"missing" : 0,
"total" : 2,
"other" : 0,
"terms" : [ {
"term" : "dr5reg58fn01",
"count" : 1
}, {
"term" : "6gyf5hkrg606",
"count" : 1
} ]
}
}

--