Sum of two fields into a one custom field

Hi ,

I am new to elasticsearch, I have a requirement like, i have data indexed into elasticsearch, which contains all string fields. I need to do sum of two fields among them into one custom field. Is it possible to perform sum on two string fields using elasticsearch query. If its possible, kindly give me some examples.

Thank you very much in advance for your response.


May be using a script field. See

But I'd recommend doing that at index time as this will slow your queries.

You can use the ingest pipeline feature and put your script there.

Hi David,

Thank you for your reply, but I wanted whether this will work for String type fields or only for numeric fields.


As long as it's a script it will work with whatever you want. I'm not telling you how to write the script though. Which I don't know as I'm not using painless.

I always prefer modifying my data before indexing it.

thank you very much for your suggestion, but my project requirement is in this way, so i need to go this way.


Good luck.

Out of curiosity, do you know why it's a requirement ?

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