How I can get 2 fields values in Elastic Search

I am trying as follows :

  • Create visualization of custom field, which is addition of 2 available fields. How I can get this, so in my dashboard data updates automatically.
1 Like

Hello @SivaK

Please share more information about the data you have and what is your expectations?

If you have 2 number fields & you need a custom field created as sum of these 2 number fields below can be a simple formula :

Thanks!!

1 Like

Thanks for responding back .. !! Yes this works for the fields with values. If the field is keyword then do we have any possible ways for enabling the similar functionality.

Example , price.keyword provides 200, tax.keyword provides 100 and now I want to have custom-sum of price.keyword and tax.keyword

Hello @SivaK

You will have to create a runtime field from this .keyword field if you want to perform sum on keyword fields.

Similar post :

Thanks!!

1 Like

There are other approaches too, for example @SivaK should maybe revisit the index's mapping for these fields. "price" would seem to be naturally a number, similarly (in this context) "tax". Maybe sometimes the field is presented with (eg) a currency symbol, e.g. $12, or other messiness, which can often be handled in an index pipeline.

Hello @Tortoise ,

Do we have any example on how to include in runtime ?

Thanks ..!!

Hello @SivaK

Could you please share the data/mapping without which we cannot suggest anything.

Example was from the tax.keyword field i will have to create a new runtime field with name tax_r with a script which will convert the value to number & this field could be used as a sum on dashboard.

Thanks!!

Hi @SivaK

What version are you on?

Can you provide a couple of actual examples of your docs?

This would be fairly trivial using ESQL with the EVAL operator which allows you to do math and casting