Non Numeric Range Facet

Hi all,

I'm new to the elastic search boards. As a long time Endeca user, I'm really enjoying working with ElasticSearch.

I would like to know if it is currently possible to generate a range facet against string data. Basically provide a range based on the String.compareTo function

Essentially something like this
"facets" : {
"Letters" : {
"range" : {
"key_script" : "_source.title",
"value_script" : "_source.title",
"ranges" : [
{ "from" : "A", "to" : "I" },
{ "from" : "I", "to" : "N" },
{ "from" : "N" }
]
}
}
}

I could obviously bake in the ranges at index time and do a simple term facet if I had to.
I was able to use a script (using js) to sort of achieve this goal - but I don't think I can get overlapping ranges like I can in the range facet, unless the script could return an array of term values - that would be cool :slight_smile:

"facets" : {
"Title A-Z" : {
"terms" : {
"fields" : ["title.titleSort"],
"size" : 10,
"script" : "var x={"A":"A-E","B":"A-E","C":"A-E","D":"A-E","E":"A-E","F":"F-M"}; var y=x[term.substring(0,1).toUpperCase()]; y==null ? "Others" : y"
}
}
}
I'm super impressed how fast this runs on my laptop on a 35K record index. Awesome work!

Is there a convenient way to plug in additional Facet types?

Thanks,

-Joe

There isn't a range facet support for string fields, can be added ... . One option is to use a set of filter facets (Elasticsearch Platform — Find real-time answers at scale | Elastic), each filter includes the relevant range using a range filter. It should be faster compared to what you are doing now (especially for subsequent executions).
On Tuesday, April 26, 2011 at 6:35 PM, joec wrote:

Hi all,

I'm new to the Elasticsearch boards. As a long time Endeca user, I'm really
enjoying working with Elasticsearch.

I would like to know if it is currently possible to generate a range facet
against string data. Basically provide a range based on the String.compareTo
function

Essentially something like this
"facets" : {
"Letters" : {
"range" : {
"key_script" : "_source.title",
"value_script" : "_source.title",
"ranges" : [
{ "from" : "A", "to" : "I" },
{ "from" : "I", "to" : "N" },
{ "from" : "N" }
]
}
}
}

I could obviously bake in the ranges at index time and do a simple term
facet if I had to.
I was able to use a script (using js) to sort of achieve this goal - but I
don't think I can get overlapping ranges like I can in the range facet,
unless the script could return an array of term values - that would be cool
:slight_smile:

"facets" : {
"Title A-Z" : {
"terms" : {
"fields" : ["title.titleSort"],
"size" : 10,
"script" : "var
x={"A":"A-E","B":"A-E","C":"A-E","D":"A-E","E":"A-E","F":"F-M"};
var y=x[term.substring(0,1).toUpperCase()]; y==null ? "Others" : y"
}
}
}
I'm super impressed how fast this runs on my laptop on a 35K record index.
Awesome work!

Is there a convenient way to plug in additional Facet types?

Thanks,

-Joe

--
View this message in context: http://elasticsearch-users.115913.n3.nabble.com/Non-Numeric-Range-Facet-tp2866042p2866042.html
Sent from the Elasticsearch Users mailing list archive at Nabble.com.