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

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Stéphane Raux
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

--


Reply | Threaded
Open this post in threaded view
|

Re: terms facets : problem when using script_field on an object containing an array

Stéphane Raux
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 <[hidden email]>:

> 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

--