我想将下面的ES查询转换为Java API
{
"sort": [
{
"nested_objects.Value": {
"order": "desc",
"nested_path": "nested_objects",
"nested_filter": {
"term": { "nested_objects.Key": "abc" }
}
}
}
]
}
试图按如下所示编写查询,但看起来以前的工作方法现已在ES 6.2中弃用
FieldSortBuilder mySort = SortBuilders.fieldSort("nested_objects.Value")
.setNestedFilter(QueryBuilders.nestedQuery("nested_objects",
QueryBuilders.termQuery("nested_objects.Key", "abc"), ScoreMode.Avg))
.order(SortOrder.DESC);
setNestedFilter()似乎已被弃用了吗?
答案 0 :(得分:0)
org.elasticsearch.search.sort.FieldSortBuilder.getNestedFilter()
set nested sort with FieldSortBuilder.setNestedSort(NestedSortBuilder) and retrieve with FieldSortBuilder.getNestedSort()
org.elasticsearch.search.sort.FieldSortBuilder.getNestedPath()
set nested sort with FieldSortBuilder.setNestedSort(NestedSortBuilder) and retrieve with FieldSortBuilder.getNestedSort()
您可以看到他们如何提到您需要利用NestedSortBuilder
下面是您可以做的。只需使用QueryBuilder
创建一个术语查询,然后在链接到setFilter
的{{1}}方法中使用它即可。
setNestedSort
希望有帮助!