# Term facet on geo\_point field

**URL:** <https://discuss.elastic.co/t/term-facet-on-geo-point-field/9973>\
**Category:** Elasticsearch\
**Created:** [December 6, 2012, 4:12pm UTC](https://discuss.elastic.co/t/term-facet-on-geo-point-field/9973 "2012-12-06T16:12:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Telvis\_Calhoun\_Jr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/telvis_calhoun_jr/32/1792_2.png) [@Telvis\_Calhoun\_Jr](https://discuss.elastic.co/u/Telvis_Calhoun_Jr)\
**Post date:** [December 6, 2012, 4:12pm UTC](https://discuss.elastic.co/t/term-facet-on-geo-point-field/9973/1 "2012-12-06T16:12:22Z")

</div>

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  
> > } ]  
> > }  
> > }

--

---

<div class="post-metadata">

**Author:** ![Anil\_Rhemtulla](https://avatars.discourse-cdn.com/v4/letter/a/b19c9b/32.png) [@Anil\_Rhemtulla](https://discuss.elastic.co/u/Anil_Rhemtulla)\
**Post date:** [December 6, 2012, 6:25pm UTC](https://discuss.elastic.co/t/term-facet-on-geo-point-field/9973/2 "2012-12-06T18:25:31Z")

</div>

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 🙂

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  
> > > } ]  
> > > }  
> > > }

--

---

<div class="post-metadata">

**Author:** ![Telvis\_Calhoun\_Jr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/telvis_calhoun_jr/32/1792_2.png) [@Telvis\_Calhoun\_Jr](https://discuss.elastic.co/u/Telvis_Calhoun_Jr)\
**Post date:** [December 6, 2012, 7:26pm UTC](https://discuss.elastic.co/t/term-facet-on-geo-point-field/9973/3 "2012-12-06T19:26:39Z")

</div>

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: [multi-field with geo\_point in a nested document · GitHub](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 🙂
> 
> 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  
> > > > } ]  
> > > > }  
> > > > }

--

---

<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, 3:01am UTC](https://discuss.elastic.co/t/term-facet-on-geo-point-field/9973/4 "2017-07-06T03:01:03Z")

</div>


