Problem with aggs queries returning null?

Hello,
I'm having trouble getting a simple aggs query to return data.

GET mydata1/_search
{
  "aggs": {
    "avg_num_days": {
     "avg": {
       "field": "myField"
     }
    }
  }
}

I was getting an error:

"error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "Field [myField] of type [keyword] is not supported for aggregation [avg]"
      }

I did some searches on the internet and found I needed this field to be a long, not a keyword as aggs don't work on keywords. I deleted the index and tried to do a PUT explicit mapping, but since the index is gone that wont work. I know I have to get this declared before the index is created, but what is the proper way change the datatype for this single field so I can run aggs against it?

All the other fields are automatically mapped properly by Elasticsearch when I import the data, a single CVS, standalone file that I upload to Kibana.

Thank you,
James

You will have to explicitly specify the field type in the index mappings either during index creation type or in an index template.

If you use Kibana to upload a CSV file, there is a box that allows you to specify the index mappings.

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