I have a really simple index with the following mapping:
PUT /localindex-products
{
"mappings": {
"properties": {
"name": { "type": "text" },
"sku": { "type": "keyword" },
"description": { "type": "text" },
"contextual": {
"properties": {
"name": { "type": "text" },
"value": { "type": "text" }
}
},
"attributes": {
"type": "nested",
"properties": {
"name": { "type": "text" },
"value": { "type": "text" }
}
}
}
}
}
All documents look like this:
{
"name" : "Shoes Adidas Falcon Male",
"sku" : "TUD-0485-001-37",
"description" : "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras ornare posuere dolor, in efficitur leo porttitor consequat. Donec consectetur urna leo, eget condimentum nisi aliquam ut. Phasellus gravida congue purus, non aliquam odio consequat et. Aenean in sollicitudin mi. Vivamus convallis erat sem, at egestas dui convallis non.",
"contextual" : [
{
"name" : "Composition",
"value" : "Upper: Textile and synthetic. Midsole: EVA. Sole: rubber, reinforced heel."
},
{
"name" : "Warranty",
"value" : "Against Manufacturing Defect."
}
],
"attributes" : [
{
"name" : "Gender",
"value" : "Male"
},
{
"name" : "Recommendation",
"value" : "Walking"
},
{
"name" : "Material",
"value" : "Synthetic and Textile"
},
{
"name" : "Color",
"value" : "Black/White"
},
{
"name" : "Size",
"value" : "37"
}
]
}
Now, I can aggregate by attributes.values
:
"aggs": {
"attributes": {
"nested": {
"path": "attributes"
},
"aggs": {
"values": {
"terms": {
"field": "attributes.value",
"size": 10
},
"aggs": {
"back_to_root": {
"reverse_nested": {
"path": "_source"
}
}
}
}
}
}
}
But the code below returns all attribute values. What I want is return attributes aggregated by names. For example, Gender > [ Male, Female ], Color > [ Black/White, Blue, Green ], Size > [ 37, 38, 39 ] and so on...
How can I do this?