我将以下数据放入了弹性搜索。
POST movies/movie
{
"title": "Apocalypse Now",
"director": "Francis Ford Coppola",
"year": 1979,
"genres": ["Drama", "War", "Foo"]
}
POST movies/movie
{
"title": "Apocalypse Now",
"director": "Francis Ford Coppola",
"year": 1979,
"genres": ["Drama", "War", "Foo", "Bar"]
}
POST movies/movie
{
"title": "Apocalypse Now",
"director": "Francis Ford Coppola",
"year": 1979,
"genres": ["Drama", "Comic", "Bar"]
}
我想得到以下结果。
"Drama" : 3
"War" : 2
"Foo" : 2
"Bar" : 2
"Comic" : 1
如何获得这些结果? 感谢您为解决此问题所提供的帮助。 预先感谢。
答案 0 :(得分:1)
您可以使用terms
aggregation,如下所示:
POST movies/_search
{
"size": 0,
"aggs": {
"counts": {
"terms": {
"field": "genres.keyword",
"size": 20
}
}
}
}