My documents looks like this:
[
{
'user_id': 1,
'search_text': 'hi',
'searched_departments': ["dep4", "dep5", "dep6"]
},
{
'user_id': 1,
'search_text': 'hi there',
'searched_departments': ["dep4", "dep6"]
},
{
'user_id': 5,
'search_text': 'I like candy',
'searched_departments': ["dep4", "dep11", "dep999"]
},
{
'user_id': 2,
'search_text': 'hi',
'searched_departments': ["dep4", "dep6", "dep7"]
}
]
I want to do an aggregation that returns the count of each department, so in this case I want my end result to be something like:
{
"dep4" : 4,
"dep6" : 3,
"dep5" : 1,
# and so on
}
my mapping:
{'mappings': {'properties': {'date': {'type': 'date'},
'searched_departments': {'type': 'text'},
'search_text': {'type': 'text'},
'user_id': {'type': 'text'}}}