Claus Ibsen created CAMEL-26233:
-----------------------------------

             Summary: camel-opensearch - a built IndexRequest body is indexed 
as a document, and a JSON search body keeps only its query (size, sort and aggs 
dropped)
                 Key: CAMEL-26233
                 URL: https://issues.apache.org/jira/browse/CAMEL-26233
             Project: Camel
          Issue Type: Bug
          Components: camel-opensearch
            Reporter: Claus Ibsen
             Fix For: 4.24.0


Found while adding the catalog body types of opensearch (CAMEL-24961, PR 
#28398). camel-elasticsearch has the same code and the same bugs (separate 
issue).

h4. 1. A built request in the body is not used as the request

{{OpensearchProducer.resolveOperation}} (main 2a465aa4814c, lines 107-134) 
picks the operation from a built request in the body ({{IndexRequest}}, 
{{GetRequest}}, {{SearchRequest}}...), but {{OpensearchActionRequestConverter}} 
only accepts the builders. A built {{IndexRequest}} goes to 
{{builder.document(document)}} (line 109), so the request object itself is 
indexed with a generated id; a built {{GetRequest}} or {{SearchRequest}} fails 
with "Wrong body type". Checked on 4.24.0-SNAPSHOT with Elasticsearch 9.1.0 and 
OpenSearch 3.9.0 from test-infra (docker).

Proposed: use a built request as is (or stop resolving the operation from built 
requests).

h4. 2. A JSON search body keeps only its query

{{toSearchRequestBuilder}} (line 257) keeps only the {{query}} member of a JSON 
text body, so {{size}}, {{sort}}, {{aggs}} and the rest are dropped without a 
warning; a Map body whose {{query}} value is not a Map fails with a 
{{ClassCastException}} (line 251). Read in the code, not run.

Proposed: pass the whole JSON to the request builder (still accepting a bare 
query).

h4. 3. DeleteIndex ignores the index name in a String body

{{toDeleteIndexRequestBuilder}} (lines 196-198) accepts a String body but takes 
the index from the {{indexName}} header or option only; with neither the call 
fails with "index / indices is missing" or "no such index [null]". Checked on 
4.24.0-SNAPSHOT with Elasticsearch 9.1.0 and OpenSearch 3.9.0 from test-infra 
(docker).

Proposed: use the String body as the index name when the header is not set.

h4. 4. Index/Update with no body or a File: unclear result

{{toIndexRequestBuilder}} (line 109) passes any other body to 
{{builder.document(...)}}: a null body fails with a Jackson exception or a 
server 500, and a {{java.io.File}} is written as a JSON string of its path. 
Checked on 4.24.0-SNAPSHOT with Elasticsearch 9.1.0 and OpenSearch 3.9.0 from 
test-infra (docker).

Proposed: fail with a clear message for a null body, and read a File as JSON 
content.

_Claude Code on behalf of davsclaus_



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to