Can I do a sum on the fields that have 'keyword' type

I have a field that is keyword type. The index looks like this:

{
"key": 1
},
{
"key": 2
},
{
"key": 3
},
{
"key":"abc"
},
{
"key":"zyx"
}

Some values are numeric and some are strings. Is there a way to sum all numeric keywords such that the value comes to 1+2+3 = 6

Is some form type casting possible?

The only way I see to do this would be with a runtime field but this will be slow most likely...
The runtime field could emit 0 when not a number and the number when it can be transformed as a number.
Then you can aggregate with a sum agg on that field I think.

Have a look at Sum aggregation | Elasticsearch Guide [8.7] | Elastic

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