# Making fields aggregate-able

**URL:** <https://discuss.elastic.co/t/making-fields-aggregate-able/65296>\
**Category:** Elasticsearch\
**Created:** [November 8, 2016, 5:29am UTC](https://discuss.elastic.co/t/making-fields-aggregate-able/65296 "2016-11-08T05:29:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![midget2000x](https://avatars.discourse-cdn.com/v4/letter/m/bbe5ce/32.png) [@midget2000x](https://discuss.elastic.co/u/midget2000x)\
**Post date:** [November 8, 2016, 5:29am UTC](https://discuss.elastic.co/t/making-fields-aggregate-able/65296/1 "2016-11-08T05:29:46Z")

</div>

I'm just digging into aggregations and in my testing, I'm running into this problem:

"Fielddata is disabled on text fields by default. Set fielddata=true on [skuid] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory."

Ultimate, I want to be able to aggregate options of items (like sizes). Here's an example:

```auto
...
	"options" : {
      "size" : [
        {
          "description" : "Small",
          "code" : "S"
        },
        {
          "code" : "M",
          "description" : "Medium"
        },
        {
          "description" : "Large",
          "code" : "L"
        },
        {
          "code" : "XXL",
          "description" : "Extra Large"
        },
        {
          "code" : "XXL",
          "description" : "XXL"
        }
      ]
    }
...

```

I found this in the docs:  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/fielddata.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/fielddata.html)

But it's not entirely clear to me how to change the mapping of that data (right now it's just the default) so that it can be used for aggregation. Anyone got any ideas?

Once I _do_ have the mapping figured out, I'm thinking something like this should work?

```auto
    "aggs" : {
        "sizes" : {
            "terms" : { 
            	"field" : "options.size.description"
             }
        }
    }

```

---

<div class="post-metadata">

**Author:** ![small-tomorrow](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/small-tomorrow/32/13319_2.png) [@small-tomorrow](https://discuss.elastic.co/u/small-tomorrow)\
**Post date:** [November 15, 2016, 12:02pm UTC](https://discuss.elastic.co/t/making-fields-aggregate-able/65296/2 "2016-11-15T12:02:23Z")

</div>

have you solved this problem ? I run into the same problem too

---

<div class="post-metadata">

**Author:** ![midget2000x](https://avatars.discourse-cdn.com/v4/letter/m/bbe5ce/32.png) [@midget2000x](https://discuss.elastic.co/u/midget2000x)\
**Post date:** [November 15, 2016, 3:43pm UTC](https://discuss.elastic.co/t/making-fields-aggregate-able/65296/3 "2016-11-15T15:43:14Z")

</div>

I haven't solved this problem in particular. I flattened out my data because it didn't really need to be structured with 3 levels.

BUT I think that would probably work if the options field was mapped like this:

```
"options" => {
    type => 'keyword'
}
```

---

<div class="post-metadata">

**Author:** ![small-tomorrow](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/small-tomorrow/32/13319_2.png) [@small-tomorrow](https://discuss.elastic.co/u/small-tomorrow)\
**Post date:** [November 16, 2016, 2:17am UTC](https://discuss.elastic.co/t/making-fields-aggregate-able/65296/4 "2016-11-16T02:17:40Z")

</div>

I was confused ,since I put not\_analyzed to my field , that means it is not a text field . although I fix it by set fielddata=true

---

<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:** [December 14, 2016, 2:17am UTC](https://discuss.elastic.co/t/making-fields-aggregate-able/65296/5 "2016-12-14T02:17:52Z")

</div>

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