Consider the following, I have a ratings and posts index.
The ratings doc is structured like:
{
"postId": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
},
"analyzer": "keyword",
"fielddata": true
},
"value": {
"type": "long"
}
}
The posts doc is structured like:
{
"postId": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
},
"analyzer": "keyword",
"fielddata": true
},
... other fields
}
Is it possible in a single query to aggregate all the ratings, sort them by highest value field and then return the posts documents that are associated with each of those values?
I've needed to do this for awhile now but have always just done extra steps to add the aggregated value field to the posts document whenever it gets updated. This doesn't seem to scale the best and it would be wonderful if I could accomplish this in a single query.
I'm using ES v6.6.2
Thanks!