Parse error with CompositeAggregation

I have tried to achieve composite aggregation in my elastic query and I'm successfully able to receive results with regular elastic search query.

Just a FYI I use date histogram aggregation with composite aggregation along with multiple sum sub aggregations.

But when tried the same with java API, the query is getting formed as expected using the searchSourceBuilder class . But an additional field "missing_bucket" is getting added to the DateHistogram query because I'm using DateHistogramValuesSourceBuilder which extends CompositeValuesSourceBuilder. The objects of the CompositeValuesSourceBuilder includes "missing_bucket" field and when DateHistogramValuesSourceBuilder is trying parse my query , it fails with the below exception.

org.elasticsearch.ElasticsearchException: Elasticsearch exception [type=illegal_argument_exception, reason=[date_histogram] unknown field [missing_bucket], parser not found]

My java code:

public ResponseDocument findbytime(String adapterName, String type, Integer duration) throws IOException {

SearchRequest searchRequest = new SearchRequest("adapter");

SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();

searchSourceBuilder.query(QueryBuilders

. boolQuery ().must(QueryBuilders. rangeQuery ("from.start").gte(returnFromDate(type, duration))

.lte("now-1m/m").format("epoch_millis"))

.must(QueryBuilders. matchQuery ("adapter_name", adapterName)));

List<CompositeValuesSourceBuilder<?>> sources = new ArrayList<>();

sources.add(randomDateHistogramSourceBuilder());

searchSourceBuilder.aggregation( new CompositeAggregationBuilder("my_buckets", sources)

.subAggregation(AggregationBuilders. sum ("success_add").field("calls_out.success"))

Query generated from the above code
{
"query": {
"bool": {
"must": [
{
"range": {
"from.start": {
"from": "now-24h",
"to": "now-1m/m",
"include_lower": true,
"include_upper": true,
"format": "epoch_millis",
"boost": 1
}
}
},
{
"match": {
"adapter_name": {
"query": "Philips",
"operator": "OR",
"prefix_length": 0,
"max_expansions": 50,
"fuzzy_transpositions": true,
"lenient": false,
"zero_terms_query": "NONE",
"auto_generate_synonyms_phrase_query": true,
"boost": 1
}
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
},
"aggregations": {
"my_buckets": {
"composite": {
"size": 10,
"sources": [
{
"date": {
"date_histogram": {
"field": "from.start",
"missing_bucket": false,
"value_type": "date",
"order": "asc",
"interval": "1h"
}
}
}
],
"aggregations": {
"success_add": {
"sum": {
"field": "calls_out.success"
}
}
}
}
}
}
}

Refer the github issues for more details https://github.com/elastic/elasticsearch/issues/39008

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.