I have an index that stores sales by salesperson, and each sale has a service rating. Using composite
I get these separate ratings within an object by duplicating the seller ID. Is it possible to nest within a single object per seller the count per review?
This is the result I need, organized and easy to locate data:
{
[
{
"operator": 79852,
"doc_count": 1,
"reviews": {
"review": "Good",
"doc_count": 1
}
},
{
"operator": 79855,
"doc_count": 3,
"reviews": {
[
{
"review": "Good",
"doc_count": 2
},
{
"review": "Bad",
"doc_count": 1
}
]
}
}
]
}
My code currently looks like this:
{
...
"aggregations": {
"groupby": {
"composite": {
"size": 1000,
"sources": [
{
"operator": {
"terms": {
"field": "operatorId",
"missing_bucket": true,
"order": "asc"
}
}
},
{
"review": {
"terms": {
"field": "review",
"missing_bucket": true,
"order": "asc"
}
}
}
]
}
}
}
}
Result:
{
...
"hits": {
"total": 5,
"max_score": 0.0,
"hits": []
},
"aggregations": {
"groupby": {
"after_key": {
"operator": 79855,
"review": "Bad"
},
"buckets": [
{
"key": {
"operator": 79852,
"review": "Bad"
},
"doc_count": 2
},
{
"key": {
"operator": 79852,
"review": "Good"
},
"doc_count": 1
},
{
"key": {
"operator": 79852,
"review": "Regular"
},
"doc_count": 1
},
{
"key": {
"operator": 79855,
"review": "Bad"
},
"doc_count": 1
}
]
}
}
}