Optimisation of scripted aggregation

I have such aggregation.

					"source":"params['_source']['prod_list'][params['_source']['prod_list'].indexOf(params.prod) + 1]",

But it is too slow. As i understand from docs - because of parsing _source for every matching document - it is very expensive operation.

So i need some way to optimize this aggregation.
Idea of it - get next value from prod_list after matched one ("params":{"prod":6384}).

I tried to use doc.prod_list in script - but it make wrong results - items in doc.prod_list has different order than in params['_source']['prod_list'].

Does anyone have some idea?
Thanks for everyone who can help!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.