Is it possible to write a json/painless script that ignores some values?

I thought of using a scripted field or just inputting a json script when visualizing data. For example, if I wanted to calculate the average of a field named 'time', but I don't want to take into account the docs with the 'time' field that equals a negative number.

If I had 10 docs, where 2 of them have 'time' = -1, it should only take into account 8 docs in order to calculate the average.

you could filter out those documents using a range query, which is much faster than painless. Why do you specifically ask for painless, I guess I am missing something?

--Alex

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