[ 
https://issues.apache.org/jira/browse/CAMEL-26232?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Claus Ibsen resolved CAMEL-26232.
---------------------------------
    Resolution: Fixed

> camel-elasticsearch - 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-26232
>                 URL: https://issues.apache.org/jira/browse/CAMEL-26232
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-elasticsearch
>            Reporter: Claus Ibsen
>            Assignee: Andrea Cosentino
>            Priority: Major
>             Fix For: 4.24.0
>
>
> Found while adding the catalog body types of elasticsearch (CAMEL-24961, PR 
> #28398). camel-opensearch has the same code and the same bugs (separate 
> issue).
> h4. 1. A built request in the body is not used as the request
> {{ElasticsearchProducer.resolveOperation}} (main 2a465aa4814c, lines 107-125) 
> picks the operation from a built request in the body ({{IndexRequest}}, 
> {{GetRequest}}, {{SearchRequest}}...), but 
> {{ElasticsearchActionRequestConverter}} only accepts the builders. A built 
> {{IndexRequest}} goes to {{builder.document(document)}} (line 108), so the 
> request object itself is indexed as a document with a generated id instead of 
> the id in the request; a built {{GetRequest}} or {{SearchRequest}} fails with 
> "Wrong body type" (line 239). 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 and document the builders only).
> h4. 2. A JSON search body keeps only its query
> {{toSearchRequestBuilder}} (lines 251-258) keeps only the {{query}} member of 
> a JSON text body, so {{size}}, {{sort}}, {{aggs}}, {{_source}} and the rest 
> are dropped without a warning; a Map body whose {{query}} value is not a Map 
> fails with a {{ClassCastException}} (line 247). Read in the code, not run.
> Proposed: pass the whole JSON to {{SearchRequest.Builder.withJson}} (still 
> accepting a bare query for compatibility).
> h4. 3. DeleteIndex ignores the index name in a String body
> {{toDeleteIndexRequestBuilder}} (lines 190-192) 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 108) 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 (or 
> GenericFile) as JSON content.
> _Claude Code on behalf of davsclaus_



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

Reply via email to