I am trying to get categories from each record within ElasticSearch and return a collection of unique categories.
Given I have a collection of books
GET _search
{
"query": {
"match_all": {}
}
}
# Response
{
"hits": {
"hits": [
{
"_source": {
"title" : "Amazing Book",
"categories": [
{
"id" : "123",
"name" : "Comedy"
},
{
"id" : "456",
"name" : "Action"
}
],
}
},
{
"_source": {
"title" : "Other Amazing Book",
"categories": [
{
"id" : "456",
"name" : "Action"
},
{
"id" : "987",
"name" : "Romance"
}
],
}
}
]
}
}
What query would produce this output?
{
"categories": [
{
"id" : "123",
"name" : "Comedy"
},
{
"id" : "456",
"name" : "Action"
},
{
"id" : "987",
"name" : "Romance"
}
]
}