I would like to use a painless script to do some calculations. The problem is, the values are stored in different documents as time series. For example the index has a mapping of 2 fields fieldA and fieldB. There can be documents with values for both fields but usually documents with only one value for one field.
How can I use a painless script to add values of two documents e.g. sum up the latest document for each field?
Should fieldA and fieldB really be strings? If yes, you'll need to use the keyword field for the calculation (and you don't want to turn on fielddata instead). Though maybe numbers are the better choice anyway?
You could either use a check doc[<field>].size()==0 for missing fields or set it explicitly to 0 with null_value in the mapping.
Well I rather want to have the possibility that the query finds both most recent documents than excluding one of it because the calculation is useless with only one field value available...
How can a query request both independent documents and then running the script on the result?
The ugly workaround would be to parse the script query, extract the field name and do separate multi search queries for each field. Then interpret the painless script in the backend to return the result. But this would make the use of the painless script completely useless.
Let's say there are several documents in the index. Some of them have only fieldA some of them only fieldB. They could be sensor values measured at slightly different timestamps. I want to calculate the sum or run other mathematical operations with the most recent values (within a time range) of fieldAandfieldB by using the script function.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.