我有一个索引,并希望获得elasticsearch中每个特定索引类型条目的计数,但可能不会提前知道类型。如何获得elasticsearch中每种类型索引的计数?
因此,举例来说,该指数是
/events
和类型可能是
/events/type1
/events/type2
...
/events/typeN
而且我想查询索引,并说:“给我的每一个的数索引事件类型“,所以可能结果集如
/events/type1 : 40
/events/type2: 20
/events/typeN: 10
其中/ events/_count会给我
/events: 70
编辑:
imotov的答案是伟大的。尽管我很容易找到如何在JavaScript/Ajax中工作的问题。我有一些像现在这样的权利:
$.ajax({
type: 'GET',
url: 'http://localhost:9200/events/_search?search_type=count',
data: '{ "facets" : { "count_by_type" : { "terms" : { "field": "_type" }}}}',
success: function(text) {
console.log(text);
}
)}'
,但我只得到在ES元素的总数,答案的方面部分似乎缺少。
谢谢!这肯定是有道理的。我似乎无法通过JavaScript/Ajax调用来调用我的ES,但是...您有关于如何做到这一点的提示吗?现在,我有: $ .ajax({\t type:'GET', \t url:'http:// localhost:9200/events/_search?SEARCH_TYPE =计数”, \t数据: '{ “刻面”:{ “count_by_type”:{ “术语”:{ “字段”: “_type”}}}}', \t成功:功能(文本){ \t \t console.log(text); \t}, – cdietschrun
编辑。问题似乎需要发布该请求,现在我了解得更多。 – cdietschrun
某些HTTP客户端无法通过GET请求发送请求正文。所以,有时需要用'POST'替换命令。 – imotov