gpt4 book ai didi

elasticsearch - Elasticsearch 1.7文档类型聚合

转载 作者:行者123 更新时间:2023-12-03 00:42:12 26 4
gpt4 key购买 nike

我正在尝试在日期存储中汇总文档类型。查看1.7 Type Filter documentation,使用类型过滤器很简单。但是,在尝试提交该查询时遇到了以下问题:

curl -XGET localhost:9200/my_index/_search?pretty -d '
{ "type":
{ "value" : "my_type" }
}'

结果是:
"error" : "SearchPhaseExecutionException[Failed to execute phase [query], all shards failed;...

我成功运行以下命令:
curl -XGET localhost:9200/my_index/_search?pretty -d '
{
"aggs": {
"type_a_total": {
"filter": {
"type": {
"value": "type_a"
}
}
}
}
}'

curl -XGET localhost:9200/my_index/_search?pretty -d '
{
"aggs": {
"type_b_total": {
"filter": {
"type": {
"value": "type_b"
}
}
}
}
}'

结果是:
...
"aggregations" : {
"type_a" : {
"doc_count" : 123456789
}
}
...
"aggregations" : {
"type_b" : {
"doc_count" : 987654321
}
}
...

知道我如何才能基于 _type将它们全部归还一次吗?

最佳答案

您需要通过type查询或query查询(我的选择)将constant_score过滤器包装在filtered元素内。

curl -XGET localhost:9200/my_index/_search?pretty -d '{
"query": {
"filtered": {
"filter": {
"type": {
"value": "my_type"
}
}
}
}
}'

但是,如果您只想获取每种类型的文档数,则可以在 terms字段上简单地使用 _type聚合
curl -XGET localhost:9200/my_index/_search?pretty -d '{
"size": 0,
"aggs": {
"all_types": {
"terms": {
"field": "_type"
}
}
}
}'

关于elasticsearch - Elasticsearch 1.7文档类型聚合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34721443/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com