Claus Ibsen created CAMEL-26234:
-----------------------------------
Summary: camel-elasticsearch-rest-client - SEARCH ignores a JSON
query in the body and matches every document, and a leftover body wins over
CamelElasticsearchId
Key: CAMEL-26234
URL: https://issues.apache.org/jira/browse/CAMEL-26234
Project: Camel
Issue Type: Bug
Components: camel-elasticsearch
Reporter: Claus Ibsen
Fix For: 4.24.0
Found while adding the catalog body types of elasticsearch-rest-client
(CAMEL-24961, PR #28398). There is no JIRA component for
camel-elasticsearch-rest-client, so this uses camel-elasticsearch.
h4. 1. SEARCH ignores a JSON query in the body
{{ElasticsearchRestClientProducer.search}} (main 2a465aa4814c, lines 287-296)
uses the {{CamelElasticsearchSearchQuery}} header, else a Map body; a JSON text
body is converted to a Map, fails, and the request goes out with no query, so
every document matches. The PR documents this, but a JSON body is the natural
input. Checked on 4.24.0-SNAPSHOT with Elasticsearch 9.1.0 and OpenSearch 3.9.0
from test-infra (docker).
Proposed: send a JSON text body as the query when the header is not set.
h4. 2. GET_BY_ID and DELETE: a leftover body wins over CamelElasticsearchId
{{getById}} (line 250) and {{delete}} (line 266) read the id from the body
first and use the {{CamelElasticsearchId}} header only when the body is empty,
so after a previous step left a body (for example the JSON of an
INDEX_OR_UPDATE) the call uses that text as the id. Checked on 4.24.0-SNAPSHOT
with Elasticsearch 9.1.0 and OpenSearch 3.9.0 from test-infra (docker).
Proposed: prefer the header, then the body (as the other operations do).
h4. 3. {{extractDocument}} found=false branch is unreachable
{{extractDocument}} (lines 351-353) returns null when {{found}} is false, but
the low-level client throws a {{ResponseException}} for the 404 first, so
GET_BY_ID of a missing id fails instead of returning null. Checked on
4.24.0-SNAPSHOT with Elasticsearch 9.1.0 and OpenSearch 3.9.0 from test-infra
(docker).
Proposed: catch the 404 and return null (as the found=false branch means to),
or remove the branch.
h4. 4. The doc names the headers INDEX_NAME and ID
{{elasticsearch-rest-client-component.adoc}} says to set the headers
{{INDEX_NAME}} and {{ID}}; the constants are {{CamelElasticsearchIndexName}}
and {{CamelElasticsearchId}} ({{ElasticSearchRestClientConstant}} lines 24 and
34). Not fixed in the PR.
Proposed: use the real header names in the operations table.
_Claude Code on behalf of davsclaus_
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)