# Problem with aggs queries returning null?

**URL:** <https://discuss.elastic.co/t/problem-with-aggs-queries-returning-null/314529>\
**Category:** Kibana\
**Created:** [September 15, 2022, 4:57pm UTC](https://discuss.elastic.co/t/problem-with-aggs-queries-returning-null/314529 "2022-09-15T16:57:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![JamesD\_7](https://avatars.discourse-cdn.com/v4/letter/j/e495f1/32.png) [@JamesD\_7](https://discuss.elastic.co/u/JamesD_7)\
**Post date:** [September 15, 2022, 4:57pm UTC](https://discuss.elastic.co/t/problem-with-aggs-queries-returning-null/314529/1 "2022-09-15T16:57:31Z")

</div>

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

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

```

I was getting an error:

```auto
"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

---

<div class="post-metadata">

**Author:** ![hendry.lim](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hendry.lim/32/71328_2.png) [@hendry.lim](https://discuss.elastic.co/u/hendry.lim)\
**Post date:** [September 15, 2022, 11:17pm UTC](https://discuss.elastic.co/t/problem-with-aggs-queries-returning-null/314529/2 "2022-09-15T23:17:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 13, 2022, 11:17pm UTC](https://discuss.elastic.co/t/problem-with-aggs-queries-returning-null/314529/3 "2022-10-13T23:17:56Z")

</div>

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