Range Facets on script_fields?

Hi,

I would like to know if it's possible to create a Range Facet on
script_fields ?

Here is my request :

{
"fields" : ["id", "name"],
"query" : {
"text" : { "type": "mytype" }
},
"script_fields" : {
"average" : {
"script" : "(_source.rate1 + _source.rate2) / 2"
}
},
"facets" : {
"average" : {
"range" : {
"field" : "average",
"ranges" : [
{ "to" : 4 },
{ "from" : 4, "to" : 6 },
{ "from" : 6, "to" : 8 },
{ "from" : 10 }
]
}
}
}
}

This request fails ... I've tried with "script_fields" : "average",
"key_field" : "average", but no result ...

It's possible on Term Facet, but I didn't find how to make it on Range
Facet ...
Is it possible ?

Thanks in advance.
Jérémy

script fields are only applicable to the top N docs that you get back (computed and returned), not for the total hits you get. Facets work on all the hits (and because of that, using _source is not recommended, because it means you load it and parse it for each hit out of the total hits). Check the range facet docs: Elasticsearch Platform — Find real-time answers at scale | Elastic, you can have an option to provide a key script and a value script.

On Thursday, March 8, 2012 at 8:12 PM, Jarnoult wrote:

Hi,

I would like to know if it's possible to create a Range Facet on
script_fields ?

Here is my request :

{
"fields" : ["id", "name"],
"query" : {
"text" : { "type": "mytype" }
},
"script_fields" : {
"average" : {
"script" : "(_source.rate1 + _source.rate2) / 2"
}
},
"facets" : {
"average" : {
"range" : {
"field" : "average",
"ranges" : [
{ "to" : 4 },
{ "from" : 4, "to" : 6 },
{ "from" : 6, "to" : 8 },
{ "from" : 10 }
]
}
}
}
}

This request fails ... I've tried with "script_fields" : "average",
"key_field" : "average", but no result ...

It's possible on Term Facet, but I didn't find how to make it on Range
Facet ...
Is it possible ?

Thanks in advance.
Jérémy