I am storing Book Titles in elasticsearch and they all belong to many shops. Like this:
{
"books": [
{
"id": 1,
"title": "Title 1",
"store": "store1"
},
{
"id": 2,
"title": "Title 1",
"store": "store2"
},
{
"id": 3,
"title": "Title 1",
"store": "store3"
},
{
"id": 4,
"title": "Title 2",
"store": "store2"
},
{
"id": 5,
"title": "Title 2",
"store": "store3"
}
]
}
How can I get all the books and group them by title... and one result per group (one row with group with the same title so i can get all ids and stores)?
Based on data above I want to get two results with all ids and stores in them.
Expected results:
{
"hits":{
"total" : 2,
"hits" : [
{
"0" : {
"title" : "Title 1",
"group": [
{
"id": 1,
"store": "store1"
},
{
"id": 2,
"store": "store2"
},
{
"id": 3,
"store": "store3"
},
]
}
},
{
"1" : {
"title" : "Title 2",
"group": [
{
"id": 4,
"store": "store2"
},
{
"id": 5,
"store": "store3"
}
]
}
}
]
}
}