Terms facets : problem when using script_field on an object containing an array


(Stéphane Raux) #1

Hi,

I am trying to use a term facet with a script_field parameter.
It works well when I use it on a simple field, or when I use it whith
a simple object (like '{"object":{"key":"value"}}'), but it seems to
fail when I try to use it on an object containing an array.

Here is a gist example (with facets output and errors) :

The first query also yielded a strange result, with a missing value.

Does anyone have any insight about what is going on ?

Thanks,

Stéphane

--


(Stéphane Raux) #2

I finally found the answer : you have to use the mvel projection
operator to iterate over the collection :
http://mvel.codehaus.org/MVEL+2.0+Projections+and+Folds

I my example, you can do :
{
"terms" : {
"script_field" : "(field in _source.array)",
"size" : 10
}
instead of "script_field" : "_source.array.field"

This does not explains why the "a" element is not taken in account in
the first facets performed on the index, though.

Best,

Stéphane

2012/9/26 Stéphane Raux stephane.raux@gmail.com:

Hi,

I am trying to use a term facet with a script_field parameter.
It works well when I use it on a simple field, or when I use it whith
a simple object (like '{"object":{"key":"value"}}'), but it seems to
fail when I try to use it on an object containing an array.

Here is a gist example (with facets output and errors) :
https://gist.github.com/3788994

The first query also yielded a strange result, with a missing value.

Does anyone have any insight about what is going on ?

Thanks,

Stéphane

--


(system) #3