# How to make filed as aggregatable in Elastic search

**URL:** <https://discuss.elastic.co/t/how-to-make-filed-as-aggregatable-in-elastic-search/272636>\
**Category:** Elasticsearch\
**Created:** [May 11, 2021, 5:40am UTC](https://discuss.elastic.co/t/how-to-make-filed-as-aggregatable-in-elastic-search/272636 "2021-05-11T05:40:26Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Suvarna\_S](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/suvarna_s/32/84391_2.png) [@Suvarna\_S](https://discuss.elastic.co/u/Suvarna_S)\
**Post date:** [May 11, 2021, 5:40am UTC](https://discuss.elastic.co/t/how-to-make-filed-as-aggregatable-in-elastic-search/272636/1 "2021-05-11T05:40:26Z")

</div>

Hi Team,

I am new to elastic search/kibana.  
I have a field _ **"exceptions"** _. I want to make this field as aggregatable, so that I can use this field for my visualization dashboard to fetch the count of exceptions. Kindly help me to fix this.

Please find the mapping here:

```auto
{
  "rs-glsss" : {
    "mappings" : {
      "properties" : {
        "@timestamp" : {
          "type" : "date"
        },
        "corelationId" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "exceptions" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "host" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "hostName" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "level" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "logMessage" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "logger" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "serviceName" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "serviceNameByLog" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "statusCode" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "thread" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "timestamp" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        }
      }
    }
  }
}

```

Need help!

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [May 11, 2021, 5:48am UTC](https://discuss.elastic.co/t/how-to-make-filed-as-aggregatable-in-elastic-search/272636/2 "2021-05-11T05:48:00Z")

</div>

Aggregate on exceptions.keyword.

---

<div class="post-metadata">

**Author:** ![Suvarna\_S](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/suvarna_s/32/84391_2.png) [@Suvarna\_S](https://discuss.elastic.co/u/Suvarna_S)\
**Post date:** [May 11, 2021, 5:48am UTC](https://discuss.elastic.co/t/how-to-make-filed-as-aggregatable-in-elastic-search/272636/3 "2021-05-11T05:48:34Z")

</div>

No.. for the field "exceptions"

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/c/b/cbcf5287876de0373c399c170e5100940bbd8876.png)

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [May 11, 2021, 6:02am UTC](https://discuss.elastic.co/t/how-to-make-filed-as-aggregatable-in-elastic-search/272636/4 "2021-05-11T06:02:01Z")

</div>

That field has two mappings. The keyword subfield can be aggregated and has the same data.

---

<div class="post-metadata">

**Author:** ![Suvarna\_S](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/suvarna_s/32/84391_2.png) [@Suvarna\_S](https://discuss.elastic.co/u/Suvarna_S)\
**Post date:** [May 11, 2021, 6:08am UTC](https://discuss.elastic.co/t/how-to-make-filed-as-aggregatable-in-elastic-search/272636/5 "2021-05-11T06:08:40Z")

</div>

Please help me to fix this.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [May 11, 2021, 6:37am UTC](https://discuss.elastic.co/t/how-to-make-filed-as-aggregatable-in-elastic-search/272636/6 "2021-05-11T06:37:58Z")

</div>

I have given the solution. Try it. I would also recommend you read [this part of the docs](https://www.elastic.co/guide/en/elasticsearch/reference/7.11/multi-fields.html).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 11, 2021, 7:01am UTC](https://discuss.elastic.co/t/how-to-make-filed-as-aggregatable-in-elastic-search/272636/7 "2021-05-11T07:01:46Z")

</div>

To answer your question;

> [@Suvarna\_S](#):
>
> I have a field _ **"exceptions"** _ . I want to make this field as aggregatable,

You need to change the mapping and use a `keyword` type.

---

<div class="post-metadata">

**Author:** ![rsmith013](https://avatars.discourse-cdn.com/v4/letter/r/e480ec/32.png) [@rsmith013](https://discuss.elastic.co/u/rsmith013)\
**Post date:** [May 12, 2021, 9:00am UTC](https://discuss.elastic.co/t/how-to-make-filed-as-aggregatable-in-elastic-search/272636/8 "2021-05-12T09:00:59Z")

</div>

The solution depends on whether you want search capability for the `exceptions` fields as well as aggregation capability.

If you want to use Elasticsearch's search capability then you should do as @Christian_Dahlqvist has said. Use `exceptions.keyword` as your aggregation field. As stated, this has the same data but has not been put through elastic's field analyzers and been tokenized.

This does not require a change to your mapping or a reindex of the data.  
If you can change the mapping and re-index and will only want to use the value of the field as a whole, not in parts (i.e. full string matching) then changing the mapping for the field to a `keyword` type, as @dadoonet suggests, will have the same effect and aggregations can then be done on the `exceptions` field natively.

To be clear, there is no difference in the result of the aggregation between using `exceptions.keyword` and changing the field to type `keyword` and using `exceptions` in your aggregations, but it will change what else you can do with the field.

---

<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:** [June 9, 2021, 9:01am UTC](https://discuss.elastic.co/t/how-to-make-filed-as-aggregatable-in-elastic-search/272636/9 "2021-06-09T09:01:29Z")

</div>

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