gpt4 book ai didi

elasticsearch - ElasticSearch将其余查询转换为运输客户端Java代码

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

在此先感谢您的帮助,

我创建了一个 flex 搜索_search查询,如下所示:

{
"size" : 0,
"aggs": {
"attrs_root": {
"nested": {
"path": "tags"
},
"aggs": {
"scope_term": {
"terms": {
"field": "tags.scope.keyword"
},
"aggs": {
"tag_term": {
"terms": {
"field": "tags.tag.keyword"
}
}
}
}
}
}
}
}

现在,我想在Java Elastic Search Transport Client 6.2中转换此查询。我尝试使用下面的代码,但未返回相同结果。 :
               NestedAggregationBuilder nested = AggregationBuilders.nested("attrs_root", "tags");
NestedAggregationBuilder subAggregation = nested
.subAggregation(AggregationBuilders.terms("scope_term").field("tags.scope.keyword"));
subAggregation = subAggregation.subAggregation(AggregationBuilders.terms("tag_term").field("tags.tag.keyword"));
requestBuilder.addAggregation(nested);
response = requestBuilder.execute().actionGet();

您能否让我知道我如何获得相同的结果?

再次感谢!

最佳答案

这是一个好的开始,但是您只需要将scope_term作为子聚合添加到嵌套的attrs_root聚合中:

NestedAggregationBuilder nested = AggregationBuilders.nested("attrs_root", "tags");
TermsAggregationBuilder field = AggregationBuilders.terms("scope_term").field("tags.scope.keyword");
field.subAggregation(AggregationBuilders.terms("tag_term").field("tags.tag.keyword"));

// add the next line
nested.subAggregation(field);

关于elasticsearch - ElasticSearch将其余查询转换为运输客户端Java代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56487884/

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