i am trying to rewrite my code from elasticsearch version 7.10.2 to latest version es 8.9 but i am having some problems:
code version 7.10.2:
FilterAggregationBuilder filteredAggs = AggregationBuilders
.filter(newsCategory.CategoryID + "",
termQuery("ListTreeCategory", "g" + newsCategory.CategoryID + "g"))
.subAggregation(terms("byActivedDate").field("NewsID")
.order(BucketOrder.aggregation("activedDateDescending", false))
.subAggregation(max("activedDateDescending").field("ActivedDate"))
.size(newsQuery.PageSize)
.subAggregation(AggregationBuilders.topHits("topActivedDate").size(1).from(0)
.sort("ActivedDate", SortOrder.DESC).fetchSource(topHitIncludes, null)));
builder.aggregation(filteredAggs)
code version 8.9
`
<Map<String, Aggregation> map = new HashMap<>();
Aggregation subAggregation3 = new Aggregation.Builder().topHits(TopHitsAggregation.of(t -> t
.field("topActivedDate")
.size(1)
.from(0))).build();
Aggregation subAggregation2 = new Aggregation.Builder()
.max(new MaxAggregation.Builder().field("ActivedDate").build())
.aggregations("subAggregation3",subAggregation3).build();
Aggregation subAggregation1 = new Aggregation.Builder()
.filter(ElasticsearchQueryBuilder.terms("ListTreeCategory", "g" + newsCategory.getCategoryID() + "g"))
.aggregations("subAggregation2",subAggregation2)
.build();
Aggregation aggregations = new Aggregation.Builder()
.terms(new TermsAggregation.Builder().field("NewsID")
.order(NamedValue.of("activedDateDescending", SortOrder.Asc))
.size(newsQuery.getPageSize()).build())
.aggregations("activedDateDescending",subAggregation1).build(); `
SortOptions sb = new SortOptions.Builder()
.field(f -> f
.field("ActivedDate")
.order(SortOrder.Desc)).build();
map.put(newsCategory.getCategoryID() + "", aggregations);
searchRequest.aggregations(map).sort(sb).source(SourceConfig.of(sou -> sou.filter(in -> in.includes(Arrays.asList(topHitIncludes)))));
I got the following error and don't know how to solve it, please help:
co.elastic.clients.elasticsearch._types.ElasticsearchException: [es/search] failed: [parsing_exception] Unknown key for a VALUE_STRING in [field].