我试图在聚合上列出所有桶,但它似乎只显示前10个 .
我的搜索:
curl -XPOST "http://localhost:9200/imoveis/_search?pretty=1" -d'
{
"size": 0,
"aggregations": {
"bairro_count": {
"terms": {
"field": "bairro.raw"
}
}
}
}'
返回:
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 16920,
"max_score" : 0.0,
"hits" : [ ]
},
"aggregations" : {
"bairro_count" : {
"buckets" : [ {
"key" : "Barra da Tijuca",
"doc_count" : 5812
}, {
"key" : "Centro",
"doc_count" : 1757
}, {
"key" : "Recreio dos Bandeirantes",
"doc_count" : 1027
}, {
"key" : "Ipanema",
"doc_count" : 927
}, {
"key" : "Copacabana",
"doc_count" : 842
}, {
"key" : "Leblon",
"doc_count" : 833
}, {
"key" : "Botafogo",
"doc_count" : 594
}, {
"key" : "Campo Grande",
"doc_count" : 456
}, {
"key" : "Tijuca",
"doc_count" : 361
}, {
"key" : "Flamengo",
"doc_count" : 328
} ]
}
}
}
这个聚合我有10个以上的密钥 . 在这个例子中,我有145个键,我想要每个键的计数 . 桶上有一些分页吗?我可以得到所有这些吗?
我正在使用Elasticsearch 1.1.0
4 回答
在你的术语聚合中将大小(第二大小)增加到10000,并且你将得到大小为10000的桶 . 默认情况下它设置为10.另外如果你想看到搜索结果只是将第一个大小设置为1,你可以看到1文档,因为ES确实支持搜索和聚合 .
但BTW,https://github.com/elasticsearch/elasticsearch/issues/1776
在6月22日关闭,我的弹性搜索在那天之前下载并安装,所以假设如果有最新版本,你可以得到它
size参数应该是术语查询示例的参数:
正如文档中所提到的仅适用于1.1.0版本
编辑
根据@PhaedrusTheGreek评论更新答案 .
设置
size:0
在2.x以后已弃用,原因是群集上存在高基数字段值的内存问题 . 您可以在github issue here中阅读更多相关信息 .建议为
size
明确设置1到2147483647之间的数字的合理值 .注意
"size":10000
获取最多10000个桶 . 默认值为10 ."size":0
结果,"hits"
默认包含10个文档 . 我们不需要它们 .默认情况下,桶按
doc_count
按递减顺序排序 .因为fielddata is disabled on text fields by default . 如果您没有明确选择字段类型映射,则它具有default dynamic mappings for string fields .
所以,不要写
"field": "your_field"
,而是需要"field": "your_field.keyword"
.