Making fields aggregate-able

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:

...
	"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

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?

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

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

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'
}

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

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