elasticsearch - Elastic Search Aggregation with scripting giving exception -
query failed [failed execute main query]]; nested: groovyscriptexecutionexception[arrayindexoutofboundsexception[-1]];
i using following aggs query
{ "aggs": { "hscodes_eval": { "terms": { "field": "fscode" }, "aggs": { "top_6_fscodes": { "terms": { "field": "fscode", "script": "doc[\"fscode\"].value[0..6]" } } } } } }
i want count of documents matching first 6 characters of field fscode. getting above exception.please help.
try this:
{ "aggs": { "hscodes_eval": { "terms": { "field": "fscode" }, "aggs": { "top_6_fscodes": { "terms": { "script": "fieldvalue=doc['fscode'].value;if(fieldvalue.length()>=7) fieldvalue[0..6] else ''" } } } } } }
but wouldn't this, meaning using script
. scripts slow , if have many documents, can add pretty quickly.
haven't thought this, gut feeling says try, at indexing time, put in sub-field of fscode
first 6 characters of initial fscode
, maybe using truncate filter. then, @ search time, use terms
aggregation not on fscode
, on subfield defined.
Comments
Post a Comment