Field has been missed in aggregate

Hi all,
I am trying to build a data table visualize so that show sum of my field named as "amount". for this purpose, i am trying to use sum aggregation in the metric part but i cannot find my field in the "field" part. it is noted that there are two "amount" fields as "amount" and "amount.keyword" that type of them are string. amount.keyword field is as following which it seems is aggregatable:

amount field is as following which it seems it is not aggregatable:


I cannot see neither "amount" nor "amount.keyword" in aggregation of visualize. how can i handle this issue? any advise will be so appreciated. Regards

having a .keyword variant of a field is the default behavior of Elasticsearch: https://www.elastic.co/blog/strings-are-dead-long-live-strings

They refer to the same data, they are just indexed in a different way. When you want to aggregate, amount.keyword is the right field to use - you can overwrite the shown name in the visualization.

I cannot see neither "amount" nor "amount.keyword" in aggregation of visualize

What aggregation are you trying to use? A keyword field can be used with "Unique count", "Terms" and "Significant terms"

many thanks for your reply. i want to use sum aggregation. how can i use amount.keyword for sum?

If amount is actually a number, then the mapping of your index in Elasticsearch is wrong - recreate your index with the right mapping (specifying amount is a number): https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html#create-mapping , then reindex your existing data https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html

After that, recreate your index pattern in Kibana and the field will be recognized as number

Many thanks. yes amount is number. does type of previous saved documents and also new ones of this field change?

You need to update existing documents by reindexing them into a new index with the correct mapping for the amount field. Check out the links I provided in my previous answer.

many thanks for your reply. updating mapping faced with following message:

PUT /my_index/_mapping/reqres
{
    "properties": {
      


              "amount" : {
            
          "type": "long" 
    
    
            }
            }
      }

error message:

{
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "mapper [amount] of different type, current_type [text], merged_type [long]"
      }
    ],
    "type": "illegal_argument_exception",
    "reason": "mapper [amount] of different type, current_type [text], merged_type [long]"
  },
  "status": 400
}

You need to create a new index for this, then use the re-index api to move data over.

1 Like

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