# Faceting on geohash in 0.90.2

**URL:** <https://discuss.elastic.co/t/faceting-on-geohash-in-0-90-2/12755>\
**Category:** Elasticsearch\
**Created:** [July 11, 2013, 1:16pm UTC](https://discuss.elastic.co/t/faceting-on-geohash-in-0-90-2/12755 "2013-07-11T13:16:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gian\_Luca\_Ortelli](https://avatars.discourse-cdn.com/v4/letter/g/e68b1a/32.png) [@Gian\_Luca\_Ortelli](https://discuss.elastic.co/u/Gian_Luca_Ortelli)\
**Post date:** [July 11, 2013, 1:16pm UTC](https://discuss.elastic.co/t/faceting-on-geohash-in-0-90-2/12755/1 "2013-07-11T13:16:55Z")

</div>

Hi,

I just learnt from [http://www.elasticsearch.org/blog/0-90-2-released/](http://www.elasticsearch.org/blog/0-90-2-released/) about  
the improved support for geohashes, and I particularly like that fact that  
they can be indexed as edge ngrams.

The blog post highlights the advantage of this when filtering, but I wanted  
to see it action with faceting as well, so I set up my index mapping as:

...  
"location" : {  
"type" : "geo\_point",  
"geohash\_prefix": true  
},  
...

then I indexed some documents containing a location field with coordinates  
and asked the facet below:

{  
"size": 0,  
"query": {  
"match\_all": {}  
},  
"facets": {  
"location": {  
"terms": {  
"field": "location",  
"regex" : ".{4}"  
}  
}  
}  
}

In order to group docs with identical values in the first 4 characters of  
the geohash. But this is not working: I don't get any facet back, unless I  
change the regex to _.{12}_, the length of the full geohash.

After some failed attempts I replaced the regex stuff with

"script" : "term.substring(0, 4)"

and I see the facets, but still I would expect the other method to work as  
well. Have I misunderstood something? Or is there a different and better  
way to implement this kind of faceting?

Gianluca

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![chilling](https://avatars.discourse-cdn.com/v4/letter/c/b3f665/32.png) [@chilling](https://discuss.elastic.co/u/chilling)\
**Post date:** [July 12, 2013, 2:40pm UTC](https://discuss.elastic.co/t/faceting-on-geohash-in-0-90-2/12755/2 "2013-07-12T14:40:16Z")

</div>

Hi Gian,

have you verified your field maps to the geo\_point type? I just missed the  
property part. So it should look like:

curl -XPUT '[http://127.0.0.1:9200/index/?pretty=true](http://127.0.0.1:9200/index/?pretty=true)' -d '{  
"mappings" : {  
"type": {  
"properties": {  
"location": {  
"type": "geo\_point",  
"geohash": true,  
"geohash\_prefix": true  
}  
}  
}  
}  
}'

Then you can simply call:

curl -XGET '[http://127.0.0.1:9200/index/\_search?pretty=true](http://127.0.0.1:9200/index/_search?pretty=true)' -d '{  
"query": {  
"match\_all": {}  
},  
"facets": {  
"location": {  
"terms": {  
"field": "location.geohash"  
}  
}  
}  
}'

The "location.geohash" field refers to the one storing the actual geohash  
prefixes.

I hope this helps. Cheers,  
florian

On Thursday, July 11, 2013 3:16:55 PM UTC+2, Gian Luca Ortelli wrote:

> Hi,
> 
> I just learnt from [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/blog/0-90-2-released/about) the improved support for geohashes, and I particularly like that fact  
> that they can be indexed as edge ngrams.
> 
> The blog post highlights the advantage of this when filtering, but I  
> wanted to see it action with faceting as well, so I set up my index mapping  
> as:
> 
> ...  
> "location" : {  
> "type" : "geo\_point",  
> "geohash\_prefix": true  
> },  
> ...
> 
> then I indexed some documents containing a location field with coordinates  
> and asked the facet below:
> 
> {  
> "size": 0,  
> "query": {  
> "match\_all": {}  
> },  
> "facets": {  
> "location": {  
> "terms": {  
> "field": "location",  
> "regex" : ".{4}"  
> }  
> }  
> }  
> }
> 
> In order to group docs with identical values in the first 4 characters of  
> the geohash. But this is not working: I don't get any facet back, unless I  
> change the regex to _.{12}_, the length of the full geohash.
> 
> After some failed attempts I replaced the regex stuff with
> 
> "script" : "term.substring(0, 4)"
> 
> and I see the facets, but still I would expect the other method to work as  
> well. Have I misunderstood something? Or is there a different and better  
> way to implement this kind of faceting?
> 
> Gianluca

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Gian\_Luca\_Ortelli](https://avatars.discourse-cdn.com/v4/letter/g/e68b1a/32.png) [@Gian\_Luca\_Ortelli](https://discuss.elastic.co/u/Gian_Luca_Ortelli)\
**Post date:** [July 12, 2013, 3:53pm UTC](https://discuss.elastic.co/t/faceting-on-geohash-in-0-90-2/12755/3 "2013-07-12T15:53:06Z")

</div>

Yes, it does help! I assumed that geohash\_prefix=true would imply  
geohash=true, therefore I never tried including it in the mapping.

Now the regex parameter works as expected.

Thanks,  
Gianluca

On Friday, July 12, 2013 4:40:16 PM UTC+2, Florian Schilling wrote:

> Hi Gian,
> 
> have you verified your field maps to the geo\_point type? I just missed the  
> property part. So it should look like:
> 
> curl -XPUT '[http://127.0.0.1:9200/index/?pretty=true](http://127.0.0.1:9200/index/?pretty=true)' -d '{  
> "mappings" : {  
> "type": {  
> "properties": {  
> "location": {  
> "type": "geo\_point",  
> "geohash": true,  
> "geohash\_prefix": true  
> }  
> }  
> }  
> }  
> }'
> 
> Then you can simply call:
> 
> curl -XGET '[http://127.0.0.1:9200/index/\_search?pretty=true](http://127.0.0.1:9200/index/_search?pretty=true)' -d '{  
> "query": {  
> "match\_all": {}  
> },  
> "facets": {  
> "location": {  
> "terms": {  
> "field": "location.geohash"  
> }  
> }  
> }  
> }'
> 
> The "location.geohash" field refers to the one storing the actual geohash  
> prefixes.
> 
> I hope this helps. Cheers,  
> florian
> 
> On Thursday, July 11, 2013 3:16:55 PM UTC+2, Gian Luca Ortelli wrote:
> 
> > Hi,
> > 
> > I just learnt from [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/blog/0-90-2-released/about) the improved support for geohashes, and I particularly like that fact  
> > that they can be indexed as edge ngrams.
> > 
> > The blog post highlights the advantage of this when filtering, but I  
> > wanted to see it action with faceting as well, so I set up my index mapping  
> > as:
> > 
> > ...  
> > "location" : {  
> > "type" : "geo\_point",  
> > "geohash\_prefix": true  
> > },  
> > ...
> > 
> > then I indexed some documents containing a location field with  
> > coordinates and asked the facet below:
> > 
> > {  
> > "size": 0,  
> > "query": {  
> > "match\_all": {}  
> > },  
> > "facets": {  
> > "location": {  
> > "terms": {  
> > "field": "location",  
> > "regex" : ".{4}"  
> > }  
> > }  
> > }  
> > }
> > 
> > In order to group docs with identical values in the first 4 characters of  
> > the geohash. But this is not working: I don't get any facet back, unless I  
> > change the regex to _.{12}_, the length of the full geohash.
> > 
> > After some failed attempts I replaced the regex stuff with
> > 
> > "script" : "term.substring(0, 4)"
> > 
> > and I see the facets, but still I would expect the other method to work  
> > as well. Have I misunderstood something? Or is there a different and better  
> > way to implement this kind of faceting?
> > 
> > Gianluca

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 2:26am UTC](https://discuss.elastic.co/t/faceting-on-geohash-in-0-90-2/12755/4 "2017-07-06T02:26:44Z")

</div>


