Andrea Cosentino created CAMEL-24814:
----------------------------------------

             Summary: camel-elasticsearch/camel-opensearch: 
BulkRequestAggregationStrategy returns the wrong exchange, breaking bulk 
aggregation
                 Key: CAMEL-24814
                 URL: https://issues.apache.org/jira/browse/CAMEL-24814
             Project: Camel
          Issue Type: Bug
          Components: camel-elasticsearch, camel-opensearch
            Reporter: Andrea Cosentino
            Assignee: Andrea Cosentino


*ElasticsearchBulkRequestAggregationStrategy* and its OpenSearch twin 
*OpensearchBulkRequestAggregationStrategy* implement Camel's 
AggregationStrategy to merge multiple {{BulkOperation\[\]}} messages into a 
single {{BulkRequest}} (the documented bulk-aggregation pattern). Both build 
the merged request and store it on *newExchange* via 
{{newExchange.getIn().setBody(builder.build())}}, but then {{return 
oldExchange;}}.

On the first message of any aggregation group {{oldExchange == null}}, so the 
strategy returns {{null}}. Camel's {{AggregateProcessor}} rejects a null return 
(see AggregateProcessor: _"AggregationStrategy ... returned null which is not 
allowed"_), so the very first exchange in every group fails with a 
CamelExchangeException. Even past the first call, the returned exchange never 
carries the merged {{BulkRequest}} that was placed on {{newExchange}}. The 
strategy is therefore non-functional for its only purpose.

The bug is latent because neither component has a unit test exercising the 
strategy.

*Fix:* return {{newExchange}} (which already holds the merged BulkRequest) in 
both classes, and add a unit test covering the first-call and subsequent-call 
paths in each component.

Affects camel-elasticsearch and camel-opensearch equally.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to