Faceting on geohash in 0.90.2

Hi,

I just learnt from 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.
For more options, visit https://groups.google.com/groups/opt_out.

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' -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' -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 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.
For more options, visit https://groups.google.com/groups/opt_out.

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' -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' -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 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.
For more options, visit https://groups.google.com/groups/opt_out.