Max aggregation on .keyword field with both string and number values

I've a quite common situation: I've an index for products with a barcode field:

 "barcode": {
               "type": "text",
                "fields": {
                  "ngram": {
                    "type": "text",
                    "analyzer": "ngram",
                    "search_analyzer": "standard"
                  "keyword": {
                    "type": "keyword"

I need to get the MAX value for the barcode when it's a number: in fact in my index I could have either string values (ie. "MYBARCODE001245") or numeric values (i.e. "1234567890123"). I need to get the MAX value of numeric values.
In that even possible? I guess I need to change a little bit my schema index because I see the query can't run on my field like it is.

Thanks for your hints.

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