# How do I use a not-analyzed string field as an aggregation bucket?

**URL:** <https://discuss.elastic.co/t/how-do-i-use-a-not-analyzed-string-field-as-an-aggregation-bucket/134858>\
**Category:** Elasticsearch\
**Created:** [June 6, 2018, 6:21pm UTC](https://discuss.elastic.co/t/how-do-i-use-a-not-analyzed-string-field-as-an-aggregation-bucket/134858 "2018-06-06T18:21:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jong](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jong/32/32012_2.png) [@jong](https://discuss.elastic.co/u/jong)\
**Post date:** [June 6, 2018, 6:21pm UTC](https://discuss.elastic.co/t/how-do-i-use-a-not-analyzed-string-field-as-an-aggregation-bucket/134858/1 "2018-06-06T18:21:53Z")

</div>

My mappings:

```
config = {
    "mappings": {
        my_doc_type: {
            "dynamic": False,
            "properties": {
                "timestamp_start": {
                    "type": "date"
                },
                "timestamp_end": {
                    "type": "date"
                },

                "entity_id": {
                    "type": "string",
                    "index": "not_analyzed"
                },

                "version": {
                    "type": "string",
                    "index": "not_analyzed"
                },
            }
        },
    ...
}

```

If I perform this query:

```
{
  "aggregations": {
    "by_entity_id": {
      "terms": {
        "field": "entity_id"
      }
    }
  },
  "from": 0,
  "query": {
    "filtered": {
      "filter": {
        "range": {
          "timestamp_end": {
            "from": "2018-04-07T18:00:17Z",
            "to": "2018-06-06T18:00:17Z"
          }
        }
      }
    }
  },
  "size": 0
}

```

My entity\_id field still seems parsed and tokenized (this data set should have exactly one entity\_id bucket):

```
{
  "aggregations": {
    "by_entity_id": {
      "buckets": [
        {
          "doc_count": 480,
          "key": "4bcf"
        },
        {
          "doc_count": 480,
          "key": "60965392"
        },
        {
          "doc_count": 480,
          "key": "73ba"
        },
        {
          "doc_count": 480,
          "key": "bb1f"
        },
        {
          "doc_count": 480,
          "key": "ff0cf25f5480"
        }
      ],
      "doc_count_error_upper_bound": 0,
      "sum_other_doc_count": 0
    }
  },
  "items": [],
  "total": 480
}

```

What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![jong](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jong/32/32012_2.png) [@jong](https://discuss.elastic.co/u/jong)\
**Post date:** [June 11, 2018, 7:54pm UTC](https://discuss.elastic.co/t/how-do-i-use-a-not-analyzed-string-field-as-an-aggregation-bucket/134858/2 "2018-06-11T19:54:28Z")

</div>

The problem here ended up being that my mappings were not getting set correctly (actually not at all). Once set correctly, the mapping started working correctly - DOH!

---

<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:** [July 9, 2018, 7:54pm UTC](https://discuss.elastic.co/t/how-do-i-use-a-not-analyzed-string-field-as-an-aggregation-bucket/134858/3 "2018-07-09T19:54:45Z")

</div>

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