I have following documents indexed in elastic search
{
"_index": "ecommerce",
"_type": "products",
"_id": "12895",
"_score": 1,
"_source": {
"title": "Blue Armani Jeans",
"slug": "blue-armani-jeans",
"price": 200,
"sale_price": 0,
"vendor_id": 62,
"featured": 0,
"viewed": 0,
"stock": 1,
"sku": "arm-jeans",
"brand": "",
"rating": 0,
"active": 0,
"vendor_name": "Armani",
"category": [
"Men Fashion",
"Casual Wear"
],
"image": "armani-jeans.jpg",
"variations": [
{
"variation_id": "32",
"stock": 10,
"price": 199,
"variation_image": "",
"sku": "arm-jeans-11",
"Size": "38",
"Color": "Blue"
},
{
"variation_id": "33",
"stock": 10,
"price": 199,
"variation_image": "",
"sku": "arm-jeans-12",
"Size": "40",
"Color": "Blue"
}
]
}
},
And i am using a query which gets all the filter variations to be shown with aggregation.
Query:
{
"size": 0,
"aggs": {
"variations": {
"nested": {
"path": "variations"
},
"aggs": {
"size": {
"terms": {
"field": "variations.Size"
}
},
"color": {
"terms": {
"field": "variations.Color"
}
},
"brand": {
"reverse_nested": {},
"aggs": {
"brand": {
"value_count": {
"field": "brand"
}
}
}
}
}
}
}
}
Output :
"color": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 543,
"buckets": [
{
"key": "black",
"doc_count": 298
},
{
"key": "blue",
"doc_count": 227
},
{
"key": "brown",
"doc_count": 170
},
{
"key": "white",
"doc_count": 153
},
{
"key": "pink",
"doc_count": 127
},
{
"key": "grey",
"doc_count": 120
},
{
"key": "multi",
"doc_count": 99
},
{
"key": "red",
"doc_count": 89
},
{
"key": "color",
"doc_count": 81
},
{
"key": "green",
"doc_count": 76
}
]
},
"brand": {
"doc_count": 621,
"brand": {
"value": 6
}
},
"size": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 517,
"buckets": [
{
"key": "size",
"doc_count": 195
},
{
"key": "s",
"doc_count": 158
},
{
"key": "free",
"doc_count": 156
},
{
"key": "m",
"doc_count": 140
},
{
"key": "l",
"doc_count": 134
},
{
"key": "xl",
"doc_count": 102
},
{
"key": "9",
"doc_count": 69
},
{
"key": "8",
"doc_count": 68
},
{
"key": "10",
"doc_count": 67
},
{
"key": "11",
"doc_count": 61
}
]
}
The records are fine if they dont have any spaces but for variations like "free size" it splits them up into "free" and "size".
What can i do to treat them as a single variation parameter? Or is there any specialized query for this kind of situation?