This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-kamelets.git
The following commit(s) were added to refs/heads/main by this push:
new 95a72f73f Fix #3384: Elasticsearch and OpenSearch Kamelets - TLS
options, login and vector search tests, _id in the search output, words-only
search, and a RAG how-to (#3385)
95a72f73f is described below
commit 95a72f73f960a31d2e978760d093c294ae552c38
Author: Claus Ibsen <[email protected]>
AuthorDate: Mon Nov 23 22:02:16 2026 +0100
Fix #3384: Elasticsearch and OpenSearch Kamelets - TLS options, login and
vector search tests, _id in the search output, words-only search, and a RAG
how-to (#3385)
* Fix #3384: Elasticsearch and OpenSearch Kamelets - TLS options, login and
vector search tests, _id in the search output, words-only search
- elasticsearch-index-sink and elasticsearch-search-action: the
sslContextParameters option, as the OpenSearch Kamelets have.
- opensearch-*: an OpenSearch example host instead of the one of the
Elasticsearch operator.
- elasticsearch-search-action and opensearch-search-action: the id of each
document found is added as _id; the queryDsl option (default true)
searches every body as words when false, for untrusted input or AI
agents; the descriptions show a vector (knn) search.
- Tests: the index-sink tests log in (Elasticsearch with security on,
OpenSearch with the security plugin); the search tests check _id,
queryDsl=false and a vector search.
- The index sinks no longer depend on camel:gson; the Elasticsearch tests
use the same image.
- A how-to page: ask questions about your own documents with
elasticsearch-index-sink, elasticsearch-search-action (vector search) and
openai-chat-action, tried with Ollama and Elasticsearch 9.1.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y4dDmBDsSWV117kccuNf9
* docs: escape the brace of ${body} in the RAG how-to, which AsciiDoc read
as an attribute
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y4dDmBDsSWV117kccuNf9
---------
Co-authored-by: Claude Opus 5.5 <[email protected]>
---
.../camel-kamelets-catalog-sbom.json | 4 +-
docs/modules/ROOT/pages/ask-your-documents.adoc | 206 +++++++++++++++++++++
docs/modules/ROOT/pages/index.adoc | 2 +
kamelets/elasticsearch-index-sink.kamelet.yaml | 8 +-
kamelets/elasticsearch-search-action.kamelet.yaml | 31 +++-
kamelets/opensearch-index-sink.kamelet.yaml | 3 +-
kamelets/opensearch-search-action.kamelet.yaml | 26 ++-
.../main/resources/META-INF/kamelets-index.json | 4 +-
.../kamelets/elasticsearch-index-sink.kamelet.yaml | 8 +-
.../elasticsearch-search-action.kamelet.yaml | 31 +++-
.../kamelets/opensearch-index-sink.kamelet.yaml | 3 +-
.../kamelets/opensearch-search-action.kamelet.yaml | 26 ++-
.../elasticsearch-index-sink-route.citrus.it.yaml | 13 +-
.../elasticsearch-index-sink-route.yaml | 2 +
...lasticsearch-search-action-route.citrus.it.yaml | 99 +++++++++-
.../elasticsearch-search-action-route.yaml | 45 +++++
.../opensearch-index-sink-route.citrus.it.yaml | 16 +-
.../opensearch/opensearch-index-sink-route.yaml | 2 +
.../opensearch-search-action-route.citrus.it.yaml | 100 +++++++++-
.../opensearch/opensearch-search-action-route.yaml | 46 +++++
20 files changed, 630 insertions(+), 45 deletions(-)
diff --git a/camel-kamelets-sbom/camel-kamelets-catalog-sbom.json
b/camel-kamelets-sbom/camel-kamelets-catalog-sbom.json
index 23e254ab9..baa42d883 100644
--- a/camel-kamelets-sbom/camel-kamelets-catalog-sbom.json
+++ b/camel-kamelets-sbom/camel-kamelets-catalog-sbom.json
@@ -2799,7 +2799,7 @@
"dependsOn" : [ "pkg:maven/org.apache.camel/[email protected]"
]
}, {
"ref" : "kamelet:elasticsearch-index-sink",
- "dependsOn" : [ "pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]" ]
+ "dependsOn" : [ "pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]" ]
}, {
"ref" : "kamelet:elasticsearch-search-action",
"dependsOn" : [
"pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]" ]
@@ -3081,7 +3081,7 @@
"dependsOn" : [
"pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]" ]
}, {
"ref" : "kamelet:opensearch-index-sink",
- "dependsOn" : [ "pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]" ]
+ "dependsOn" : [ "pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]" ]
}, {
"ref" : "kamelet:opensearch-search-action",
"dependsOn" : [
"pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]" ]
diff --git a/docs/modules/ROOT/pages/ask-your-documents.adoc
b/docs/modules/ROOT/pages/ask-your-documents.adoc
new file mode 100644
index 000000000..e92c7f5e5
--- /dev/null
+++ b/docs/modules/ROOT/pages/ask-your-documents.adoc
@@ -0,0 +1,206 @@
+= Ask questions about your own documents
+
+This page shows how to build, with Kamelets and a few steps of Camel, a flow
that answers questions from your own documents: a question goes in, and the
answer comes back, written by an AI model from the documents that match the
question best. This is often called retrieval-augmented generation (RAG).
+
+It uses:
+
+* `elasticsearch-index-sink`, to store the documents in Elasticsearch, each
with a vector that stands for its meaning;
+* `elasticsearch-search-action`, to find the documents whose meaning is
closest to the question (a vector search);
+* `openai-chat-action`, to have an AI model answer the question from the
documents found;
+* the `embeddings` operation of the Camel `openai` component, which turns a
text into its vector.
+
+It works with OpenAI, and with any server that offers the same API, such as
https://ollama.com/[Ollama] on your own machine. The same flow works with
OpenSearch, with `opensearch-index-sink` and `opensearch-search-action`; only
the vector search is written differently (see <<opensearch>>).
+
+== What a vector is
+
+An embedding model turns a text into a list of numbers, a vector, such as
`[0.0123, -0.0456, ...]`. Texts that mean the same have vectors that are close
to each other, even when they share no words: "my invoice is wrong" is close to
"billing error on my account". So to find the documents about a question, the
flow turns the question into a vector too, and asks Elasticsearch for the
documents whose vector is closest.
+
+The documents and the questions must be turned into vectors by the same model,
and the index must know how many numbers the vectors of that model have.
+
+== What you need
+
+* Elasticsearch; this page was tried with Elasticsearch 9.1. To try it on your
machine, in a container without login:
++
+[source,shell]
+----
+docker run -d --name es -p 9200:9200 -e discovery.type=single-node -e
xpack.security.enabled=false elasticsearch:9.1.0
+----
+* An embedding model and a chat model. With Ollama:
++
+[source,shell]
+----
+ollama pull embeddinggemma:300m
+ollama pull granite4:3b
+----
++
+`granite4:3b` is a small model that runs on a laptop and answers well from the
documents it is given. With OpenAI instead, leave out the `baseUrl` parameters
below, set the `OPENAI_API_KEY` environment variable, and use an embedding
model and a chat model of OpenAI; the `dims` of the index is then the size of
the vectors of that embedding model.
+
+== Create the index
+
+Create the index before storing documents, with a field of type `dense_vector`
for the vectors. The `dims` is the number of numbers in a vector of the
embedding model: 768 for `embeddinggemma:300m`.
+
+[source,shell]
+----
+curl -X PUT localhost:9200/docs -H 'Content-Type: application/json' -d '{
+ "mappings": {"properties": {
+ "title": {"type": "text"},
+ "text": {"type": "text"},
+ "embedding": {"type": "dense_vector", "dims": 768, "similarity":
"cosine"}}}}'
+----
+
+Without this, Elasticsearch creates the index by itself when the first
document comes, and stores the vector as a list of plain numbers, which a
vector search cannot use.
+
+== The routes
+
+Save this as `ask-docs.camel.yaml`. It has two routes: `store` turns each text
file dropped in the `docs` folder into a document with its vector, and `ask`
answers the questions posted to `http://localhost:8080/ask`.
+
+[source,yaml]
+----
+- route:
+ id: store
+ from:
+ uri: "kamelet:file-watch-source"
+ parameters:
+ filePath: "docs"
+ events: "CREATE"
+ steps:
+ - convertBodyTo:
+ type: java.lang.String
+ # keep the text, as the next step replaces the body with its vector
+ - setVariable:
+ name: text
+ simple: "${body}"
+ - to:
+ uri: "openai:embeddings"
+ parameters:
+ baseUrl: "http://localhost:11434/v1"
+ embeddingModel: "embeddinggemma:300m"
+ # the body is now the vector, a List of numbers
+ - setBody:
+ simple: >-
+ {"title": "${header.CamelFileName}",
+ "text": "${escape(json,${variable.text})}",
+ "embedding": ${body}}
+ - to:
+ uri: "kamelet:elasticsearch-index-sink"
+ parameters:
+ clusterName: "docker-cluster"
+ hostAddresses: "localhost:9200"
+ enableSSL: false
+ indexName: "docs"
+
+- route:
+ id: ask
+ from:
+ uri: "platform-http:/ask"
+ steps:
+ - convertBodyTo:
+ type: java.lang.String
+ # keep the question, as the next steps replace the body
+ - setVariable:
+ name: question
+ simple: "${body}"
+ - to:
+ uri: "openai:embeddings"
+ parameters:
+ baseUrl: "http://localhost:11434/v1"
+ embeddingModel: "embeddinggemma:300m"
+ # a vector search: the 3 documents closest to the question, without
their vectors
+ - setBody:
+ simple: >-
+ {"knn": {"field": "embedding", "query_vector": ${body}, "k": 3,
"num_candidates": 50},
+ "_source": ["title", "text"]}
+ - to:
+ uri: "kamelet:elasticsearch-search-action"
+ parameters:
+ clusterName: "docker-cluster"
+ hostAddresses: "localhost:9200"
+ enableSSL: false
+ indexName: "docs"
+ size: 3
+ # the body is now a JSON array of the documents found
+ - setBody:
+ simple: |-
+ Documents:
+ ${body}
+
+ Question: ${variable.question}
+ - to:
+ uri: "kamelet:openai-chat-action"
+ parameters:
+ baseUrl: "http://localhost:11434/v1"
+ model: "granite4:3b"
+ systemMessage: >-
+ Answer the question only from the documents you are given, and
name the title of
+ the document you used. If the documents do not hold the
answer, say that you do not know.
+----
+
+== Try it
+
+Run the routes, and put a few text files in the `docs` folder once they run
(`file-watch-source` sees only the files created after it starts):
+
+[source,shell]
+----
+camel run ask-docs.camel.yaml
+mkdir -p docs
+echo "Orders can be returned within 30 days, in their original packaging. The
refund is paid within 5 working days." > docs/returns.txt
+echo "We ship to all countries in the EU. Shipping is free for orders over 50
euro." > docs/shipping.txt
+----
+
+Then ask:
+
+[source,shell]
+----
+curl -X POST localhost:8080/ask -H 'Content-Type: text/plain' -d 'How long do
I have to send something back?'
+----
+
+The answer comes from `returns.txt`, although the question does not use the
words of the document ("send something back", not "returned"):
+
+[source,text]
+----
+According to the information provided in the "returns.txt" document, orders
can be returned within 30 days.
+----
+
+The exact words differ from one run to the next. A question that the documents
do not answer, such as `What is the capital of France?`, gets `I do not know`.
+
+The `Content-Type: text/plain` matters: without it, `curl -d` sends the
question as a form, which the HTTP endpoint reads as form fields instead of a
body.
+
+== How it works
+
+* *The vector of a text.* The `embeddings` operation of the `openai` component
sends the body to the embedding model, and gives back its vector as a `List` of
numbers. Written in a Simple expression, such as `$\{body}`, the list is a JSON
array.
+* *Storing.* The route builds the document as JSON, with the text, its title
and its vector, and `elasticsearch-index-sink` stores it. `escape(json,...)`
makes any text, with quotes or line breaks, safe inside the JSON.
+* *Searching.* The body of `elasticsearch-search-action` is a search in the
Query DSL of Elasticsearch, here a `knn` search with the vector of the
question. `"_source": ["title", "text"]` leaves the vectors out of the
documents found, so that they do not fill the prompt. The action gives back the
documents found as a JSON array, best match first, each with its id in `_id`.
+* *Answering.* The route puts the documents and the question in one text, and
`openai-chat-action` sends it to the chat model, with instructions in
`systemMessage` to answer only from the documents. Its body afterwards is the
answer, which goes back to the caller of `/ask`.
+* *Variables.* Each step replaces the body, so the text and the question are
kept in variables, to be used again later in the route.
+
+[#opensearch]
+== With OpenSearch
+
+The same routes work with OpenSearch, with `opensearch-index-sink` and
`opensearch-search-action`. The index needs the setting `index.knn` and a field
of type `knn_vector`:
+
+[source,shell]
+----
+curl -X PUT localhost:9200/docs -H 'Content-Type: application/json' -d '{
+ "settings": {"index.knn": true},
+ "mappings": {"properties": {
+ "title": {"type": "text"},
+ "text": {"type": "text"},
+ "embedding": {"type": "knn_vector", "dimension": 768, "space_type":
"cosinesimil"}}}}'
+----
+
+and the vector search is a `knn` query:
+
+[source,yaml]
+----
+ - setBody:
+ simple: >-
+ {"query": {"knn": {"embedding": {"vector": ${body}, "k": 3}}},
+ "_source": ["title", "text"]}
+----
+
+== Good to know
+
+* *More documents than fit in a prompt.* The flow sends only the 3 closest
documents to the chat model. A long document is better split in parts of a few
paragraphs, each stored as its own document with its own vector, so that the
search finds the part that answers the question.
+* *Keywords and vectors.* A vector search finds texts with the same meaning,
but can miss an exact name or number, such as an order number. Elasticsearch
can combine a `knn` search with a `query` for words in the same search.
+* *The question comes from outside.* In this flow the route writes the search
itself, and the question is only a vector in it, so the caller cannot change
the search. When the body of `elasticsearch-search-action` comes from a caller,
such as an AI agent through `ai-tool-source`, set its `queryDsl` option to
false, so that the body can only be words to search for.
+* *A model change.* Vectors made by different models cannot be compared. When
the embedding model changes, store all the documents again, in an index with
the `dims` of the new model.
diff --git a/docs/modules/ROOT/pages/index.adoc
b/docs/modules/ROOT/pages/index.adoc
index 9923ee63e..d51e5dde1 100644
--- a/docs/modules/ROOT/pages/index.adoc
+++ b/docs/modules/ROOT/pages/index.adoc
@@ -9,6 +9,8 @@ Kamelets were originally born for Kubernetes and they have
eventually moved to b
Kamelets are extensible components. Look at the guide and learn
xref:development.adoc[how to develop a new Kamelet],
and xref:documenting.adoc[how to document it] for people and AI assistants
that do not know Camel.
+To see several Kamelets work together, read how to
xref:ask-your-documents.adoc[ask questions about your own documents] with
Elasticsearch and an AI model.
+
== Compatibility Matrix
[caption=]
diff --git a/kamelets/elasticsearch-index-sink.kamelet.yaml
b/kamelets/elasticsearch-index-sink.kamelet.yaml
index 050247e92..6305f73cf 100644
--- a/kamelets/elasticsearch-index-sink.kamelet.yaml
+++ b/kamelets/elasticsearch-index-sink.kamelet.yaml
@@ -79,6 +79,11 @@ spec:
description: The name of the index to store the documents in.
Elasticsearch creates it when it does not exist. The `indexName` header of a
message takes precedence.
type: string
example: orders
+ sslContextParameters:
+ title: SSL Context Parameters
+ description: For TLS settings that `certificate` cannot give, such as
a client certificate (mutual TLS), a trust store, or a TLS version, an
`SSLContextParameters` object defined in the application, as `#bean:` followed
by its name. It takes precedence over `certificate`; set one or the other.
+ type: string
+ example: "#bean:mySslContext"
certificate:
title: Certificate
description: The certificate of the certificate authority (CA) that
signed the certificate of the cluster, such as the `http_ca.crt` file that
Elasticsearch generates, as a PEM or DER file encoded in base64 on one line,
such as the output of `base64 -w0 http_ca.crt` (`base64 -i http_ca.crt` on
macOS). Needed when the cluster uses a self-signed certificate, or one signed
by a private CA. When it is set, only this CA is trusted; when it is not set,
the certificates that Java trusts [...]
@@ -127,7 +132,6 @@ spec:
- "camel:jackson3"
- "camel:kamelet"
- "camel:elasticsearch"
- - "camel:gson"
- "camel:bean"
template:
beans:
@@ -184,4 +188,4 @@ spec:
- unmarshal:
json: {}
- to:
- uri:
"{{local-es}}:{{clusterName}}?operation=INDEX&hostAddresses={{hostAddresses}}&enableSSL={{enableSSL}}&indexName={{?indexName}}&certificatePath=RAW(base64:{{?certificate}})&connectionTimeout={{?connectionTimeout}}&socketTimeout={{?socketTimeout}}"
+ uri:
"{{local-es}}:{{clusterName}}?operation=INDEX&hostAddresses={{hostAddresses}}&enableSSL={{enableSSL}}&indexName={{?indexName}}&certificatePath=RAW(base64:{{?certificate}})&sslContextParameters={{?sslContextParameters}}&connectionTimeout={{?connectionTimeout}}&socketTimeout={{?socketTimeout}}"
diff --git a/kamelets/elasticsearch-search-action.kamelet.yaml
b/kamelets/elasticsearch-search-action.kamelet.yaml
index ca95ab377..a75a1bfc6 100644
--- a/kamelets/elasticsearch-search-action.kamelet.yaml
+++ b/kamelets/elasticsearch-search-action.kamelet.yaml
@@ -36,11 +36,11 @@ spec:
Use it to look something up in the middle of a flow, for example to find
the customer of an order, or to enrich an event with the records that match it.
To store documents in Elasticsearch, use `elasticsearch-index-sink`; for
OpenSearch, use `opensearch-search-action`.
- Input: the body is the search. Text that starts with `{` is a search in
the Query DSL of Elasticsearch, as JSON text: either a query alone, such as
`{"match": {"city": "Oslo"}}`, or the body of a `_search` request with a
`query`, such as `{"query": {"match_all": {}}, "sort": [{"age": "desc"}]}`. Any
other text is searched for as words in all the fields of the documents: `Oslo
Rome` finds the documents that contain Oslo or Rome. An empty body finds
nothing. Bytes are read as text, a [...]
+ Input: the body is the search. Text that starts with `{` is a search in
the Query DSL of Elasticsearch, as JSON text: either a query alone, such as
`{"match": {"city": "Oslo"}}`, or the body of a `_search` request with a
`query`, such as `{"query": {"match_all": {}}, "sort": [{"age": "desc"}]}`. Any
other text is searched for as words in all the fields of the documents: `Oslo
Rome` finds the documents that contain Oslo or Rome. An empty body finds
nothing. Bytes are read as text, a [...]
- Output: the body is a JSON array, as text, with the documents found
(their `_source`), best match first unless the search has a `sort`, such as
`[{"name": "Alice Smith", "city": "Oslo"}]`; an empty array `[]` when nothing
matches. The `CamelElasticsearchTotalHits` header is the number of documents
that match, which can be more than the documents in the body. The
`Content-Type` header is `application/json`.
+ Output: the body is a JSON array, as text, with the documents found
(their `_source`, with the id of the document added as `_id`), best match first
unless the search has a `sort`, such as `[{"name": "Alice Smith", "city":
"Oslo", "_id": "1"}]`; an empty array `[]` when nothing matches. The
`CamelElasticsearchTotalHits` header is the number of documents that match,
which can be more than the documents in the body. The `Content-Type` header is
`application/json`.
- Good to know: the body holds at most `size` documents; a `size` in the
search is ignored. Elasticsearch stops counting the matches at 10000, so a
larger number is given as 10000. A search with `"_source": false` gives an
empty array. A search that is not valid JSON, an index that does not exist, or
a query that Elasticsearch rejects, fails the message. Headers that start with
`CamelElasticsearch` are removed from the message first, so they cannot change
the index, the operation or [...]
+ Good to know: the body holds at most `size` documents; a `size` in the
search is ignored. Elasticsearch stops counting the matches at 10000, so a
larger number is given as 10000. A search with `"_source": false` gives an
empty array. A search that is not valid JSON, an index that does not exist, or
a query that Elasticsearch rejects, fails the message. Headers that start with
`CamelElasticsearch` are removed from the message first, so they cannot change
the index, the operation or [...]
required:
- clusterName
- hostAddresses
@@ -85,6 +85,16 @@ spec:
description: The largest number of documents to give back in the body,
for each message. It takes precedence over a `size` in the search.
type: integer
default: 10
+ queryDsl:
+ title: Query DSL
+ description: Whether a body that starts with `{`, or a Map, is a
search in the Query DSL. When it is false, every body is searched for as words
in all the fields, so that whoever writes the body cannot run other queries;
set it to false when the body comes from untrusted input or from an AI agent.
+ type: boolean
+ default: true
+ sslContextParameters:
+ title: SSL Context Parameters
+ description: For TLS settings that `certificate` cannot give, such as
a client certificate (mutual TLS), a trust store, or a TLS version, an
`SSLContextParameters` object defined in the application, as `#bean:` followed
by its name. It takes precedence over `certificate`; set one or the other.
+ type: string
+ example: "#bean:mySslContext"
certificate:
title: Certificate
description: The certificate of the certificate authority (CA) that
signed the certificate of the cluster, such as the `http_ca.crt` file that
Elasticsearch generates, as a PEM or DER file encoded in base64 on one line,
such as the output of `base64 -w0 http_ca.crt` (`base64 -i http_ca.crt` on
macOS). Needed when the cluster uses a self-signed certificate, or one signed
by a private CA. When it is set, only this CA is trusted; when it is not set,
the certificates that Java trusts [...]
@@ -127,6 +137,17 @@ spec:
pattern: "CamelElasticsearch*"
- choice:
when:
+ # queryDsl=false: every body is searched for as words, whatever
it holds
+ - expression:
+ simple:
+ expression: "'{{queryDsl}}' == 'false'"
+ steps:
+ - convertBodyTo:
+ type: java.lang.String
+ - setBody:
+ expression:
+ simple:
+ expression: '{"query": {"multi_match": {"query":
"${escape(json)}"} } }'
- expression:
simple:
expression: "${body} !is 'java.util.Map'"
@@ -144,7 +165,7 @@ spec:
simple:
expression: '{"query": {"multi_match":
{"query": "${escape(json)}"} } }'
- to:
- uri:
"{{local-es}}:{{clusterName}}?operation=Search&indexName={{indexName}}&size={{size}}&documentClass=java.util.Map&hostAddresses={{hostAddresses}}&enableSSL={{enableSSL}}&certificatePath=RAW(base64:{{?certificate}})&connectionTimeout={{?connectionTimeout}}&socketTimeout={{?socketTimeout}}"
+ uri:
"{{local-es}}:{{clusterName}}?operation=Search&indexName={{indexName}}&size={{size}}&documentClass=java.util.Map&hostAddresses={{hostAddresses}}&enableSSL={{enableSSL}}&certificatePath=RAW(base64:{{?certificate}})&sslContextParameters={{?sslContextParameters}}&connectionTimeout={{?connectionTimeout}}&socketTimeout={{?socketTimeout}}"
- removeHeaders:
pattern: "CamelElasticsearch*"
- setHeader:
@@ -155,7 +176,7 @@ spec:
- setBody:
expression:
simple:
- expression: "${forEach(${body.hits},${body.source})}"
+ expression:
"${forEach(${body.hits},${mapAdd(${body.source},_id,${body.id})})}"
- marshal:
json: {}
- convertBodyTo:
diff --git a/kamelets/opensearch-index-sink.kamelet.yaml
b/kamelets/opensearch-index-sink.kamelet.yaml
index 772eef953..1ce0311f6 100644
--- a/kamelets/opensearch-index-sink.kamelet.yaml
+++ b/kamelets/opensearch-index-sink.kamelet.yaml
@@ -68,7 +68,7 @@ spec:
title: Host Addresses
description: The address of the OpenSearch HTTP API, as `host:port`,
or several nodes separated by commas. The port is 9200 by default.
type: string
- example: quickstart-es-http:9200
+ example: opensearch-cluster-master:9200
clusterName:
title: OpenSearch Cluster Name
description: The name of the OpenSearch cluster. Required, but not
checked against the cluster.
@@ -132,7 +132,6 @@ spec:
- "camel:jackson3"
- "camel:kamelet"
- "camel:opensearch"
- - "camel:gson"
- "camel:bean"
template:
beans:
diff --git a/kamelets/opensearch-search-action.kamelet.yaml
b/kamelets/opensearch-search-action.kamelet.yaml
index 37b4eae15..3346b4b10 100644
--- a/kamelets/opensearch-search-action.kamelet.yaml
+++ b/kamelets/opensearch-search-action.kamelet.yaml
@@ -36,11 +36,11 @@ spec:
Use it to look something up in the middle of a flow, for example to find
the customer of an order, or to enrich an event with the records that match it.
To store documents in OpenSearch, use `opensearch-index-sink`; for
Elasticsearch, use `elasticsearch-search-action`.
- Input: the body is the search. Text that starts with `{` is a search in
the Query DSL of OpenSearch, as JSON text: either a query alone, such as
`{"match": {"city": "Oslo"}}`, or the body of a `_search` request with a
`query`, such as `{"query": {"match_all": {}}, "sort": [{"age": "desc"}]}`. Any
other text is searched for as words in all the fields of the documents: `Oslo
Rome` finds the documents that contain Oslo or Rome. An empty body finds
nothing. Bytes are read as text, and [...]
+ Input: the body is the search. Text that starts with `{` is a search in
the Query DSL of OpenSearch, as JSON text: either a query alone, such as
`{"match": {"city": "Oslo"}}`, or the body of a `_search` request with a
`query`, such as `{"query": {"match_all": {}}, "sort": [{"age": "desc"}]}`. Any
other text is searched for as words in all the fields of the documents: `Oslo
Rome` finds the documents that contain Oslo or Rome. An empty body finds
nothing. Bytes are read as text, and [...]
- Output: the body is a JSON array, as text, with the documents found
(their `_source`), best match first unless the search has a `sort`, such as
`[{"name": "Alice Smith", "city": "Oslo"}]`; an empty array `[]` when nothing
matches. The `CamelOpensearchTotalHits` header is the number of documents that
match, which can be more than the documents in the body. The `Content-Type`
header is `application/json`.
+ Output: the body is a JSON array, as text, with the documents found
(their `_source`, with the id of the document added as `_id`), best match first
unless the search has a `sort`, such as `[{"name": "Alice Smith", "city":
"Oslo", "_id": "1"}]`; an empty array `[]` when nothing matches. The
`CamelOpensearchTotalHits` header is the number of documents that match, which
can be more than the documents in the body. The `Content-Type` header is
`application/json`.
- Good to know: the body holds at most `size` documents; a `size` in the
search is ignored. OpenSearch stops counting the matches at 10000, so a larger
number is given as 10000. A search with `"_source": false` gives an empty
array. A search that is not valid JSON, an index that does not exist, or a
query that OpenSearch rejects, fails the message. Headers that start with
`CamelOpensearch` are removed from the message first, so they cannot change the
index, the operation or the size. [...]
+ Good to know: the body holds at most `size` documents; a `size` in the
search is ignored. OpenSearch stops counting the matches at 10000, so a larger
number is given as 10000. A search with `"_source": false` gives an empty
array. A search that is not valid JSON, an index that does not exist, or a
query that OpenSearch rejects, fails the message. Headers that start with
`CamelOpensearch` are removed from the message first, so they cannot change the
index, the operation or the size. [...]
required:
- clusterName
- hostAddresses
@@ -69,7 +69,7 @@ spec:
title: Host Addresses
description: The address of the OpenSearch HTTP API, as `host:port`,
or several nodes separated by commas. The port is 9200 by default.
type: string
- example: quickstart-es-http:9200
+ example: opensearch-cluster-master:9200
clusterName:
title: OpenSearch Cluster Name
description: The name of the OpenSearch cluster. Required, but not
checked against the cluster.
@@ -85,6 +85,11 @@ spec:
description: The largest number of documents to give back in the body,
for each message. It takes precedence over a `size` in the search.
type: integer
default: 10
+ queryDsl:
+ title: Query DSL
+ description: Whether a body that starts with `{`, or a Map, is a
search in the Query DSL. When it is false, every body is searched for as words
in all the fields, so that whoever writes the body cannot run other queries;
set it to false when the body comes from untrusted input or from an AI agent.
+ type: boolean
+ default: true
sslContextParameters:
title: SSL Context Parameters
description: For TLS settings that `certificate` cannot give, such as
a client certificate (mutual TLS), a trust store, or a TLS version, an
`SSLContextParameters` object defined in the application, as `#bean:` followed
by its name. It takes precedence over `certificate`; set one or the other.
@@ -132,6 +137,17 @@ spec:
pattern: "CamelOpensearch*"
- choice:
when:
+ # queryDsl=false: every body is searched for as words, whatever
it holds
+ - expression:
+ simple:
+ expression: "'{{queryDsl}}' == 'false'"
+ steps:
+ - convertBodyTo:
+ type: java.lang.String
+ - setBody:
+ expression:
+ simple:
+ expression: '{"query": {"multi_match": {"query":
"${escape(json)}"} } }'
- expression:
simple:
expression: "${body} !is 'java.util.Map'"
@@ -160,7 +176,7 @@ spec:
- setBody:
expression:
simple:
- expression: "${forEach(${body.hits},${body.source})}"
+ expression:
"${forEach(${body.hits},${mapAdd(${body.source},_id,${body.id})})}"
- marshal:
json: {}
- convertBodyTo:
diff --git
a/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
b/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
index 16c756a17..6fe13ef1d 100644
--- a/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
+++ b/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
@@ -775,7 +775,7 @@
"supportLevel" : "Preview",
"title" : "ElasticSearch Search Action",
"summary" : "Searches an index of Elasticsearch for each message, and
gives back the documents found, as a JSON array.",
- "description" : "Searches an index of Elasticsearch for each message, and
gives back the documents found, as a JSON array.\n\nUse it to look something up
in the middle of a flow, for example to find the customer of an order, or to
enrich an event with the records that match it. To store documents in
Elasticsearch, use `elasticsearch-index-sink`; for OpenSearch, use
`opensearch-search-action`.\n\nInput: the body is the search. Text that starts
with `{` is a search in the Query DSL of [...]
+ "description" : "Searches an index of Elasticsearch for each message, and
gives back the documents found, as a JSON array.\n\nUse it to look something up
in the middle of a flow, for example to find the customer of an order, or to
enrich an event with the records that match it. To store documents in
Elasticsearch, use `elasticsearch-index-sink`; for OpenSearch, use
`opensearch-search-action`.\n\nInput: the body is the search. Text that starts
with `{` is a search in the Query DSL of [...]
"group" : "ElasticSearch",
"namespace" : "Search",
"provider" : "Apache Software Foundation"
@@ -1715,7 +1715,7 @@
"supportLevel" : "Preview",
"title" : "OpenSearch Search Action",
"summary" : "Searches an index of OpenSearch for each message, and gives
back the documents found, as a JSON array.",
- "description" : "Searches an index of OpenSearch for each message, and
gives back the documents found, as a JSON array.\n\nUse it to look something up
in the middle of a flow, for example to find the customer of an order, or to
enrich an event with the records that match it. To store documents in
OpenSearch, use `opensearch-index-sink`; for Elasticsearch, use
`elasticsearch-search-action`.\n\nInput: the body is the search. Text that
starts with `{` is a search in the Query DSL of Ope [...]
+ "description" : "Searches an index of OpenSearch for each message, and
gives back the documents found, as a JSON array.\n\nUse it to look something up
in the middle of a flow, for example to find the customer of an order, or to
enrich an event with the records that match it. To store documents in
OpenSearch, use `opensearch-index-sink`; for Elasticsearch, use
`elasticsearch-search-action`.\n\nInput: the body is the search. Text that
starts with `{` is a search in the Query DSL of Ope [...]
"group" : "OpenSearch",
"namespace" : "Search",
"provider" : "Apache Software Foundation"
diff --git
a/library/camel-kamelets/src/main/resources/kamelets/elasticsearch-index-sink.kamelet.yaml
b/library/camel-kamelets/src/main/resources/kamelets/elasticsearch-index-sink.kamelet.yaml
index 050247e92..6305f73cf 100644
---
a/library/camel-kamelets/src/main/resources/kamelets/elasticsearch-index-sink.kamelet.yaml
+++
b/library/camel-kamelets/src/main/resources/kamelets/elasticsearch-index-sink.kamelet.yaml
@@ -79,6 +79,11 @@ spec:
description: The name of the index to store the documents in.
Elasticsearch creates it when it does not exist. The `indexName` header of a
message takes precedence.
type: string
example: orders
+ sslContextParameters:
+ title: SSL Context Parameters
+ description: For TLS settings that `certificate` cannot give, such as
a client certificate (mutual TLS), a trust store, or a TLS version, an
`SSLContextParameters` object defined in the application, as `#bean:` followed
by its name. It takes precedence over `certificate`; set one or the other.
+ type: string
+ example: "#bean:mySslContext"
certificate:
title: Certificate
description: The certificate of the certificate authority (CA) that
signed the certificate of the cluster, such as the `http_ca.crt` file that
Elasticsearch generates, as a PEM or DER file encoded in base64 on one line,
such as the output of `base64 -w0 http_ca.crt` (`base64 -i http_ca.crt` on
macOS). Needed when the cluster uses a self-signed certificate, or one signed
by a private CA. When it is set, only this CA is trusted; when it is not set,
the certificates that Java trusts [...]
@@ -127,7 +132,6 @@ spec:
- "camel:jackson3"
- "camel:kamelet"
- "camel:elasticsearch"
- - "camel:gson"
- "camel:bean"
template:
beans:
@@ -184,4 +188,4 @@ spec:
- unmarshal:
json: {}
- to:
- uri:
"{{local-es}}:{{clusterName}}?operation=INDEX&hostAddresses={{hostAddresses}}&enableSSL={{enableSSL}}&indexName={{?indexName}}&certificatePath=RAW(base64:{{?certificate}})&connectionTimeout={{?connectionTimeout}}&socketTimeout={{?socketTimeout}}"
+ uri:
"{{local-es}}:{{clusterName}}?operation=INDEX&hostAddresses={{hostAddresses}}&enableSSL={{enableSSL}}&indexName={{?indexName}}&certificatePath=RAW(base64:{{?certificate}})&sslContextParameters={{?sslContextParameters}}&connectionTimeout={{?connectionTimeout}}&socketTimeout={{?socketTimeout}}"
diff --git
a/library/camel-kamelets/src/main/resources/kamelets/elasticsearch-search-action.kamelet.yaml
b/library/camel-kamelets/src/main/resources/kamelets/elasticsearch-search-action.kamelet.yaml
index ca95ab377..a75a1bfc6 100644
---
a/library/camel-kamelets/src/main/resources/kamelets/elasticsearch-search-action.kamelet.yaml
+++
b/library/camel-kamelets/src/main/resources/kamelets/elasticsearch-search-action.kamelet.yaml
@@ -36,11 +36,11 @@ spec:
Use it to look something up in the middle of a flow, for example to find
the customer of an order, or to enrich an event with the records that match it.
To store documents in Elasticsearch, use `elasticsearch-index-sink`; for
OpenSearch, use `opensearch-search-action`.
- Input: the body is the search. Text that starts with `{` is a search in
the Query DSL of Elasticsearch, as JSON text: either a query alone, such as
`{"match": {"city": "Oslo"}}`, or the body of a `_search` request with a
`query`, such as `{"query": {"match_all": {}}, "sort": [{"age": "desc"}]}`. Any
other text is searched for as words in all the fields of the documents: `Oslo
Rome` finds the documents that contain Oslo or Rome. An empty body finds
nothing. Bytes are read as text, a [...]
+ Input: the body is the search. Text that starts with `{` is a search in
the Query DSL of Elasticsearch, as JSON text: either a query alone, such as
`{"match": {"city": "Oslo"}}`, or the body of a `_search` request with a
`query`, such as `{"query": {"match_all": {}}, "sort": [{"age": "desc"}]}`. Any
other text is searched for as words in all the fields of the documents: `Oslo
Rome` finds the documents that contain Oslo or Rome. An empty body finds
nothing. Bytes are read as text, a [...]
- Output: the body is a JSON array, as text, with the documents found
(their `_source`), best match first unless the search has a `sort`, such as
`[{"name": "Alice Smith", "city": "Oslo"}]`; an empty array `[]` when nothing
matches. The `CamelElasticsearchTotalHits` header is the number of documents
that match, which can be more than the documents in the body. The
`Content-Type` header is `application/json`.
+ Output: the body is a JSON array, as text, with the documents found
(their `_source`, with the id of the document added as `_id`), best match first
unless the search has a `sort`, such as `[{"name": "Alice Smith", "city":
"Oslo", "_id": "1"}]`; an empty array `[]` when nothing matches. The
`CamelElasticsearchTotalHits` header is the number of documents that match,
which can be more than the documents in the body. The `Content-Type` header is
`application/json`.
- Good to know: the body holds at most `size` documents; a `size` in the
search is ignored. Elasticsearch stops counting the matches at 10000, so a
larger number is given as 10000. A search with `"_source": false` gives an
empty array. A search that is not valid JSON, an index that does not exist, or
a query that Elasticsearch rejects, fails the message. Headers that start with
`CamelElasticsearch` are removed from the message first, so they cannot change
the index, the operation or [...]
+ Good to know: the body holds at most `size` documents; a `size` in the
search is ignored. Elasticsearch stops counting the matches at 10000, so a
larger number is given as 10000. A search with `"_source": false` gives an
empty array. A search that is not valid JSON, an index that does not exist, or
a query that Elasticsearch rejects, fails the message. Headers that start with
`CamelElasticsearch` are removed from the message first, so they cannot change
the index, the operation or [...]
required:
- clusterName
- hostAddresses
@@ -85,6 +85,16 @@ spec:
description: The largest number of documents to give back in the body,
for each message. It takes precedence over a `size` in the search.
type: integer
default: 10
+ queryDsl:
+ title: Query DSL
+ description: Whether a body that starts with `{`, or a Map, is a
search in the Query DSL. When it is false, every body is searched for as words
in all the fields, so that whoever writes the body cannot run other queries;
set it to false when the body comes from untrusted input or from an AI agent.
+ type: boolean
+ default: true
+ sslContextParameters:
+ title: SSL Context Parameters
+ description: For TLS settings that `certificate` cannot give, such as
a client certificate (mutual TLS), a trust store, or a TLS version, an
`SSLContextParameters` object defined in the application, as `#bean:` followed
by its name. It takes precedence over `certificate`; set one or the other.
+ type: string
+ example: "#bean:mySslContext"
certificate:
title: Certificate
description: The certificate of the certificate authority (CA) that
signed the certificate of the cluster, such as the `http_ca.crt` file that
Elasticsearch generates, as a PEM or DER file encoded in base64 on one line,
such as the output of `base64 -w0 http_ca.crt` (`base64 -i http_ca.crt` on
macOS). Needed when the cluster uses a self-signed certificate, or one signed
by a private CA. When it is set, only this CA is trusted; when it is not set,
the certificates that Java trusts [...]
@@ -127,6 +137,17 @@ spec:
pattern: "CamelElasticsearch*"
- choice:
when:
+ # queryDsl=false: every body is searched for as words, whatever
it holds
+ - expression:
+ simple:
+ expression: "'{{queryDsl}}' == 'false'"
+ steps:
+ - convertBodyTo:
+ type: java.lang.String
+ - setBody:
+ expression:
+ simple:
+ expression: '{"query": {"multi_match": {"query":
"${escape(json)}"} } }'
- expression:
simple:
expression: "${body} !is 'java.util.Map'"
@@ -144,7 +165,7 @@ spec:
simple:
expression: '{"query": {"multi_match":
{"query": "${escape(json)}"} } }'
- to:
- uri:
"{{local-es}}:{{clusterName}}?operation=Search&indexName={{indexName}}&size={{size}}&documentClass=java.util.Map&hostAddresses={{hostAddresses}}&enableSSL={{enableSSL}}&certificatePath=RAW(base64:{{?certificate}})&connectionTimeout={{?connectionTimeout}}&socketTimeout={{?socketTimeout}}"
+ uri:
"{{local-es}}:{{clusterName}}?operation=Search&indexName={{indexName}}&size={{size}}&documentClass=java.util.Map&hostAddresses={{hostAddresses}}&enableSSL={{enableSSL}}&certificatePath=RAW(base64:{{?certificate}})&sslContextParameters={{?sslContextParameters}}&connectionTimeout={{?connectionTimeout}}&socketTimeout={{?socketTimeout}}"
- removeHeaders:
pattern: "CamelElasticsearch*"
- setHeader:
@@ -155,7 +176,7 @@ spec:
- setBody:
expression:
simple:
- expression: "${forEach(${body.hits},${body.source})}"
+ expression:
"${forEach(${body.hits},${mapAdd(${body.source},_id,${body.id})})}"
- marshal:
json: {}
- convertBodyTo:
diff --git
a/library/camel-kamelets/src/main/resources/kamelets/opensearch-index-sink.kamelet.yaml
b/library/camel-kamelets/src/main/resources/kamelets/opensearch-index-sink.kamelet.yaml
index 772eef953..1ce0311f6 100644
---
a/library/camel-kamelets/src/main/resources/kamelets/opensearch-index-sink.kamelet.yaml
+++
b/library/camel-kamelets/src/main/resources/kamelets/opensearch-index-sink.kamelet.yaml
@@ -68,7 +68,7 @@ spec:
title: Host Addresses
description: The address of the OpenSearch HTTP API, as `host:port`,
or several nodes separated by commas. The port is 9200 by default.
type: string
- example: quickstart-es-http:9200
+ example: opensearch-cluster-master:9200
clusterName:
title: OpenSearch Cluster Name
description: The name of the OpenSearch cluster. Required, but not
checked against the cluster.
@@ -132,7 +132,6 @@ spec:
- "camel:jackson3"
- "camel:kamelet"
- "camel:opensearch"
- - "camel:gson"
- "camel:bean"
template:
beans:
diff --git
a/library/camel-kamelets/src/main/resources/kamelets/opensearch-search-action.kamelet.yaml
b/library/camel-kamelets/src/main/resources/kamelets/opensearch-search-action.kamelet.yaml
index 37b4eae15..3346b4b10 100644
---
a/library/camel-kamelets/src/main/resources/kamelets/opensearch-search-action.kamelet.yaml
+++
b/library/camel-kamelets/src/main/resources/kamelets/opensearch-search-action.kamelet.yaml
@@ -36,11 +36,11 @@ spec:
Use it to look something up in the middle of a flow, for example to find
the customer of an order, or to enrich an event with the records that match it.
To store documents in OpenSearch, use `opensearch-index-sink`; for
Elasticsearch, use `elasticsearch-search-action`.
- Input: the body is the search. Text that starts with `{` is a search in
the Query DSL of OpenSearch, as JSON text: either a query alone, such as
`{"match": {"city": "Oslo"}}`, or the body of a `_search` request with a
`query`, such as `{"query": {"match_all": {}}, "sort": [{"age": "desc"}]}`. Any
other text is searched for as words in all the fields of the documents: `Oslo
Rome` finds the documents that contain Oslo or Rome. An empty body finds
nothing. Bytes are read as text, and [...]
+ Input: the body is the search. Text that starts with `{` is a search in
the Query DSL of OpenSearch, as JSON text: either a query alone, such as
`{"match": {"city": "Oslo"}}`, or the body of a `_search` request with a
`query`, such as `{"query": {"match_all": {}}, "sort": [{"age": "desc"}]}`. Any
other text is searched for as words in all the fields of the documents: `Oslo
Rome` finds the documents that contain Oslo or Rome. An empty body finds
nothing. Bytes are read as text, and [...]
- Output: the body is a JSON array, as text, with the documents found
(their `_source`), best match first unless the search has a `sort`, such as
`[{"name": "Alice Smith", "city": "Oslo"}]`; an empty array `[]` when nothing
matches. The `CamelOpensearchTotalHits` header is the number of documents that
match, which can be more than the documents in the body. The `Content-Type`
header is `application/json`.
+ Output: the body is a JSON array, as text, with the documents found
(their `_source`, with the id of the document added as `_id`), best match first
unless the search has a `sort`, such as `[{"name": "Alice Smith", "city":
"Oslo", "_id": "1"}]`; an empty array `[]` when nothing matches. The
`CamelOpensearchTotalHits` header is the number of documents that match, which
can be more than the documents in the body. The `Content-Type` header is
`application/json`.
- Good to know: the body holds at most `size` documents; a `size` in the
search is ignored. OpenSearch stops counting the matches at 10000, so a larger
number is given as 10000. A search with `"_source": false` gives an empty
array. A search that is not valid JSON, an index that does not exist, or a
query that OpenSearch rejects, fails the message. Headers that start with
`CamelOpensearch` are removed from the message first, so they cannot change the
index, the operation or the size. [...]
+ Good to know: the body holds at most `size` documents; a `size` in the
search is ignored. OpenSearch stops counting the matches at 10000, so a larger
number is given as 10000. A search with `"_source": false` gives an empty
array. A search that is not valid JSON, an index that does not exist, or a
query that OpenSearch rejects, fails the message. Headers that start with
`CamelOpensearch` are removed from the message first, so they cannot change the
index, the operation or the size. [...]
required:
- clusterName
- hostAddresses
@@ -69,7 +69,7 @@ spec:
title: Host Addresses
description: The address of the OpenSearch HTTP API, as `host:port`,
or several nodes separated by commas. The port is 9200 by default.
type: string
- example: quickstart-es-http:9200
+ example: opensearch-cluster-master:9200
clusterName:
title: OpenSearch Cluster Name
description: The name of the OpenSearch cluster. Required, but not
checked against the cluster.
@@ -85,6 +85,11 @@ spec:
description: The largest number of documents to give back in the body,
for each message. It takes precedence over a `size` in the search.
type: integer
default: 10
+ queryDsl:
+ title: Query DSL
+ description: Whether a body that starts with `{`, or a Map, is a
search in the Query DSL. When it is false, every body is searched for as words
in all the fields, so that whoever writes the body cannot run other queries;
set it to false when the body comes from untrusted input or from an AI agent.
+ type: boolean
+ default: true
sslContextParameters:
title: SSL Context Parameters
description: For TLS settings that `certificate` cannot give, such as
a client certificate (mutual TLS), a trust store, or a TLS version, an
`SSLContextParameters` object defined in the application, as `#bean:` followed
by its name. It takes precedence over `certificate`; set one or the other.
@@ -132,6 +137,17 @@ spec:
pattern: "CamelOpensearch*"
- choice:
when:
+ # queryDsl=false: every body is searched for as words, whatever
it holds
+ - expression:
+ simple:
+ expression: "'{{queryDsl}}' == 'false'"
+ steps:
+ - convertBodyTo:
+ type: java.lang.String
+ - setBody:
+ expression:
+ simple:
+ expression: '{"query": {"multi_match": {"query":
"${escape(json)}"} } }'
- expression:
simple:
expression: "${body} !is 'java.util.Map'"
@@ -160,7 +176,7 @@ spec:
- setBody:
expression:
simple:
- expression: "${forEach(${body.hits},${body.source})}"
+ expression:
"${forEach(${body.hits},${mapAdd(${body.source},_id,${body.id})})}"
- marshal:
json: {}
- convertBodyTo:
diff --git
a/tests/camel-kamelets-itest/src/test/resources/elasticsearch/elasticsearch-index-sink-route.citrus.it.yaml
b/tests/camel-kamelets-itest/src/test/resources/elasticsearch/elasticsearch-index-sink-route.citrus.it.yaml
index df4576f0a..30dce29de 100644
---
a/tests/camel-kamelets-itest/src/test/resources/elasticsearch/elasticsearch-index-sink-route.citrus.it.yaml
+++
b/tests/camel-kamelets-itest/src/test/resources/elasticsearch/elasticsearch-index-sink-route.citrus.it.yaml
@@ -17,12 +17,12 @@
name: elasticsearch-index-sink-route-test
actions:
- # Elasticsearch with one node and security off, so it is reached with plain
HTTP
+ # Elasticsearch with one node and security on: a login is needed (user
elastic), over plain HTTP
- testcontainers:
start:
container:
name: "elasticsearch"
- image: "docker.elastic.co/elasticsearch/elasticsearch:9.1.0"
+ image: "elasticsearch:9.1.0"
startUpTimeout: 180
exposedPorts:
- 9200
@@ -30,13 +30,17 @@ actions:
- name: "discovery.type"
value: "single-node"
- name: "xpack.security.enabled"
+ value: "true"
+ - name: "xpack.security.http.ssl.enabled"
value: "false"
+ - name: "ELASTIC_PASSWORD"
+ value: "kamelets-Test-1"
- name: "cluster.routing.allocation.disk.threshold_enabled"
value: "false"
- name: "ES_JAVA_OPTS"
value: "-Xms512m -Xmx512m"
waitFor:
- url: "http://localhost:9200/"
+ logMessage: '.*"message":"started.*'
- camel:
cli:
@@ -81,6 +85,9 @@ actions:
sendRequest:
GET:
path: "/orders/_doc/order-1"
+ headers:
+ - name: "Authorization"
+ value: "Basic citrus:encodeBase64('elastic:kamelets-Test-1')"
- http:
client:
"http://${CITRUS_TESTCONTAINERS_ELASTICSEARCH_HOST}:${CITRUS_TESTCONTAINERS_ELASTICSEARCH_PORT}"
receiveResponse:
diff --git
a/tests/camel-kamelets-itest/src/test/resources/elasticsearch/elasticsearch-index-sink-route.yaml
b/tests/camel-kamelets-itest/src/test/resources/elasticsearch/elasticsearch-index-sink-route.yaml
index 4de225c81..308e29d79 100644
---
a/tests/camel-kamelets-itest/src/test/resources/elasticsearch/elasticsearch-index-sink-route.yaml
+++
b/tests/camel-kamelets-itest/src/test/resources/elasticsearch/elasticsearch-index-sink-route.yaml
@@ -36,6 +36,8 @@
parameters:
hostAddresses: '{{elasticsearch.host}}:{{elasticsearch.port}}'
clusterName: 'docker-cluster'
+ user: 'elastic'
+ password: 'kamelets-Test-1'
indexName: 'other'
enableSSL: false
# what the Kamelet gives: the Java type of the body and the
Content-Type
diff --git
a/tests/camel-kamelets-itest/src/test/resources/elasticsearch/elasticsearch-search-action-route.citrus.it.yaml
b/tests/camel-kamelets-itest/src/test/resources/elasticsearch/elasticsearch-search-action-route.citrus.it.yaml
index da40314a1..33cc3b7a5 100644
---
a/tests/camel-kamelets-itest/src/test/resources/elasticsearch/elasticsearch-search-action-route.citrus.it.yaml
+++
b/tests/camel-kamelets-itest/src/test/resources/elasticsearch/elasticsearch-search-action-route.citrus.it.yaml
@@ -88,6 +88,53 @@ actions:
response:
status: 201
+ # an index of places with a vector of 3 numbers each, in a `dense_vector`
field, for a vector search
+ - http:
+ client:
"http://${CITRUS_TESTCONTAINERS_ELASTICSEARCH_HOST}:${CITRUS_TESTCONTAINERS_ELASTICSEARCH_PORT}"
+ sendRequest:
+ PUT:
+ path: "/places"
+ contentType: "application/json"
+ body:
+ data: '{"mappings": {"properties": {"name": {"type": "keyword"},
"embedding": {"type": "dense_vector", "dims": 3, "similarity": "cosine"}}}}'
+ - http:
+ client:
"http://${CITRUS_TESTCONTAINERS_ELASTICSEARCH_HOST}:${CITRUS_TESTCONTAINERS_ELASTICSEARCH_PORT}"
+ receiveResponse:
+ response:
+ status: 200
+ - http:
+ client:
"http://${CITRUS_TESTCONTAINERS_ELASTICSEARCH_HOST}:${CITRUS_TESTCONTAINERS_ELASTICSEARCH_PORT}"
+ sendRequest:
+ PUT:
+ path: "/places/_doc/n"
+ contentType: "application/json"
+ parameters:
+ - name: "refresh"
+ value: 'true'
+ body:
+ data: '{"name": "north", "embedding": [1.0, 0.0, 0.0]}'
+ - http:
+ client:
"http://${CITRUS_TESTCONTAINERS_ELASTICSEARCH_HOST}:${CITRUS_TESTCONTAINERS_ELASTICSEARCH_PORT}"
+ receiveResponse:
+ response:
+ status: 201
+ - http:
+ client:
"http://${CITRUS_TESTCONTAINERS_ELASTICSEARCH_HOST}:${CITRUS_TESTCONTAINERS_ELASTICSEARCH_PORT}"
+ sendRequest:
+ PUT:
+ path: "/places/_doc/e"
+ contentType: "application/json"
+ parameters:
+ - name: "refresh"
+ value: 'true'
+ body:
+ data: '{"name": "east", "embedding": [0.0, 1.0, 0.0]}'
+ - http:
+ client:
"http://${CITRUS_TESTCONTAINERS_ELASTICSEARCH_HOST}:${CITRUS_TESTCONTAINERS_ELASTICSEARCH_PORT}"
+ receiveResponse:
+ response:
+ status: 201
+
- camel:
cli:
run:
@@ -118,7 +165,7 @@ actions:
- name: "X-Content-Type"
value: 'ct=application/json'
body:
- data: '[{"name": "Alice Smith", "city": "Oslo"}]'
+ data: '[{"name": "Alice Smith", "city": "Oslo", "_id": "1"}]'
- http:
server: "searchServer"
sendResponse:
@@ -142,7 +189,7 @@ actions:
- name: "X-Content-Type"
value: 'ct=application/json'
body:
- data: '[{"name": "Bob Jones", "city": "Rome"}]'
+ data: '[{"name": "Bob Jones", "city": "Rome", "_id": "2"}]'
- http:
server: "searchServer"
sendResponse:
@@ -174,3 +221,51 @@ actions:
status: 200
reasonPhrase: "OK"
version: "HTTP/1.1"
+
+ # queryDsl=false: a Query DSL text is searched for as words, so match_all
finds nothing
+ - http:
+ server: "searchServer"
+ receiveRequest:
+ POST:
+ path: "/words"
+ type: "json"
+ headers:
+ - name: "X-Body-Type"
+ value: 'java.lang.String'
+ - name: "X-Total-Hits"
+ value: '0'
+ - name: "X-Content-Type"
+ value: 'ct=application/json'
+ body:
+ data: '[]'
+ - http:
+ server: "searchServer"
+ sendResponse:
+ response:
+ status: 200
+ reasonPhrase: "OK"
+ version: "HTTP/1.1"
+
+ # a vector search: the place whose vector is closest, with only the fields
of _source
+ - http:
+ server: "searchServer"
+ receiveRequest:
+ POST:
+ path: "/knn"
+ type: "json"
+ headers:
+ - name: "X-Body-Type"
+ value: 'java.lang.String'
+ - name: "X-Total-Hits"
+ value: '1'
+ - name: "X-Content-Type"
+ value: 'ct=application/json'
+ body:
+ data: '[{"name": "north", "_id": "n"}]'
+ - http:
+ server: "searchServer"
+ sendResponse:
+ response:
+ status: 200
+ reasonPhrase: "OK"
+ version: "HTTP/1.1"
diff --git
a/tests/camel-kamelets-itest/src/test/resources/elasticsearch/elasticsearch-search-action-route.yaml
b/tests/camel-kamelets-itest/src/test/resources/elasticsearch/elasticsearch-search-action-route.yaml
index 49db72a47..132901940 100644
---
a/tests/camel-kamelets-itest/src/test/resources/elasticsearch/elasticsearch-search-action-route.yaml
+++
b/tests/camel-kamelets-itest/src/test/resources/elasticsearch/elasticsearch-search-action-route.yaml
@@ -92,3 +92,48 @@
simple: "ct=${header.Content-Type}"
- to:
uri: "{{http.sink.url}}/none"
+ # queryDsl=false: the body is words to search for, also when it is
Query DSL
+ - setBody:
+ constant: '{"match_all": {}}'
+ - to:
+ uri: "kamelet:elasticsearch-search-action"
+ parameters:
+ hostAddresses: '{{elasticsearch.host}}:{{elasticsearch.port}}'
+ clusterName: 'docker-cluster'
+ indexName: 'customers'
+ enableSSL: false
+ queryDsl: false
+ # what the Kamelet gives: the Java type of the body, the total and the
Content-Type
+ - setHeader:
+ name: X-Body-Type
+ simple: "${body.getClass().getName()}"
+ - setHeader:
+ name: X-Total-Hits
+ simple: "${header.CamelElasticsearchTotalHits}"
+ - setHeader:
+ name: X-Content-Type
+ simple: "ct=${header.Content-Type}"
+ - to:
+ uri: "{{http.sink.url}}/words"
+ # a vector search in the Query DSL
+ - setBody:
+ constant: '{"knn": {"field": "embedding", "query_vector": [0.9,
0.1, 0.0], "k": 1, "num_candidates": 10}, "_source": ["name"]}'
+ - to:
+ uri: "kamelet:elasticsearch-search-action"
+ parameters:
+ hostAddresses: '{{elasticsearch.host}}:{{elasticsearch.port}}'
+ clusterName: 'docker-cluster'
+ indexName: 'places'
+ enableSSL: false
+ # what the Kamelet gives: the Java type of the body, the total and the
Content-Type
+ - setHeader:
+ name: X-Body-Type
+ simple: "${body.getClass().getName()}"
+ - setHeader:
+ name: X-Total-Hits
+ simple: "${header.CamelElasticsearchTotalHits}"
+ - setHeader:
+ name: X-Content-Type
+ simple: "ct=${header.Content-Type}"
+ - to:
+ uri: "{{http.sink.url}}/knn"
diff --git
a/tests/camel-kamelets-itest/src/test/resources/opensearch/opensearch-index-sink-route.citrus.it.yaml
b/tests/camel-kamelets-itest/src/test/resources/opensearch/opensearch-index-sink-route.citrus.it.yaml
index 9b6fd9823..dabf84cb4 100644
---
a/tests/camel-kamelets-itest/src/test/resources/opensearch/opensearch-index-sink-route.citrus.it.yaml
+++
b/tests/camel-kamelets-itest/src/test/resources/opensearch/opensearch-index-sink-route.citrus.it.yaml
@@ -17,7 +17,7 @@
name: opensearch-index-sink-route-test
actions:
- # OpenSearch with one node and the security plugin off, so it is reached
with plain HTTP
+ # OpenSearch with one node and the security plugin on: a login is needed
(user admin), over plain HTTP
- testcontainers:
start:
container:
@@ -29,16 +29,17 @@ actions:
env:
- name: "discovery.type"
value: "single-node"
- - name: "DISABLE_SECURITY_PLUGIN"
- value: "true"
- - name: "DISABLE_INSTALL_DEMO_CONFIG"
- value: "true"
+ - name: "OPENSEARCH_INITIAL_ADMIN_PASSWORD"
+ value: "Kamelets-Test-2026!"
+ - name: "plugins.security.ssl.http.enabled"
+ value: "false"
- name: "cluster.routing.allocation.disk.threshold_enabled"
value: "false"
- name: "OPENSEARCH_JAVA_OPTS"
value: "-Xms512m -Xmx512m"
waitFor:
- url: "http://localhost:9200/"
+ # logged once the security plugin has its configuration, so that
the login works
+ logMessage: ".*Node '.*' initialized.*"
- camel:
cli:
@@ -83,6 +84,9 @@ actions:
sendRequest:
GET:
path: "/orders/_doc/order-1"
+ headers:
+ - name: "Authorization"
+ value: "Basic citrus:encodeBase64('admin:Kamelets-Test-2026!')"
- http:
client:
"http://${CITRUS_TESTCONTAINERS_OPENSEARCH_HOST}:${CITRUS_TESTCONTAINERS_OPENSEARCH_PORT}"
receiveResponse:
diff --git
a/tests/camel-kamelets-itest/src/test/resources/opensearch/opensearch-index-sink-route.yaml
b/tests/camel-kamelets-itest/src/test/resources/opensearch/opensearch-index-sink-route.yaml
index 1c849b727..1bbb21670 100644
---
a/tests/camel-kamelets-itest/src/test/resources/opensearch/opensearch-index-sink-route.yaml
+++
b/tests/camel-kamelets-itest/src/test/resources/opensearch/opensearch-index-sink-route.yaml
@@ -36,6 +36,8 @@
parameters:
hostAddresses: '{{opensearch.host}}:{{opensearch.port}}'
clusterName: 'docker-cluster'
+ user: 'admin'
+ password: 'Kamelets-Test-2026!'
indexName: 'other'
enableSSL: false
# what the Kamelet gives: the Java type of the body and the
Content-Type
diff --git
a/tests/camel-kamelets-itest/src/test/resources/opensearch/opensearch-search-action-route.citrus.it.yaml
b/tests/camel-kamelets-itest/src/test/resources/opensearch/opensearch-search-action-route.citrus.it.yaml
index 53702be5a..b9647484b 100644
---
a/tests/camel-kamelets-itest/src/test/resources/opensearch/opensearch-search-action-route.citrus.it.yaml
+++
b/tests/camel-kamelets-itest/src/test/resources/opensearch/opensearch-search-action-route.citrus.it.yaml
@@ -90,6 +90,53 @@ actions:
response:
status: 201
+ # an index of places with a vector of 3 numbers each, in a `knn_vector`
field, in an index with `index.knn`, for a vector search
+ - http:
+ client:
"http://${CITRUS_TESTCONTAINERS_OPENSEARCH_HOST}:${CITRUS_TESTCONTAINERS_OPENSEARCH_PORT}"
+ sendRequest:
+ PUT:
+ path: "/places"
+ contentType: "application/json"
+ body:
+ data: '{"settings": {"index.knn": true}, "mappings":
{"properties": {"name": {"type": "keyword"}, "embedding": {"type":
"knn_vector", "dimension": 3, "space_type": "cosinesimil"}}}}'
+ - http:
+ client:
"http://${CITRUS_TESTCONTAINERS_OPENSEARCH_HOST}:${CITRUS_TESTCONTAINERS_OPENSEARCH_PORT}"
+ receiveResponse:
+ response:
+ status: 200
+ - http:
+ client:
"http://${CITRUS_TESTCONTAINERS_OPENSEARCH_HOST}:${CITRUS_TESTCONTAINERS_OPENSEARCH_PORT}"
+ sendRequest:
+ PUT:
+ path: "/places/_doc/n"
+ contentType: "application/json"
+ parameters:
+ - name: "refresh"
+ value: 'true'
+ body:
+ data: '{"name": "north", "embedding": [1.0, 0.0, 0.0]}'
+ - http:
+ client:
"http://${CITRUS_TESTCONTAINERS_OPENSEARCH_HOST}:${CITRUS_TESTCONTAINERS_OPENSEARCH_PORT}"
+ receiveResponse:
+ response:
+ status: 201
+ - http:
+ client:
"http://${CITRUS_TESTCONTAINERS_OPENSEARCH_HOST}:${CITRUS_TESTCONTAINERS_OPENSEARCH_PORT}"
+ sendRequest:
+ PUT:
+ path: "/places/_doc/e"
+ contentType: "application/json"
+ parameters:
+ - name: "refresh"
+ value: 'true'
+ body:
+ data: '{"name": "east", "embedding": [0.0, 1.0, 0.0]}'
+ - http:
+ client:
"http://${CITRUS_TESTCONTAINERS_OPENSEARCH_HOST}:${CITRUS_TESTCONTAINERS_OPENSEARCH_PORT}"
+ receiveResponse:
+ response:
+ status: 201
+
- camel:
cli:
run:
@@ -120,7 +167,7 @@ actions:
- name: "X-Content-Type"
value: 'ct=application/json'
body:
- data: '[{"name": "Alice Smith", "city": "Oslo"}]'
+ data: '[{"name": "Alice Smith", "city": "Oslo", "_id": "1"}]'
- http:
server: "searchServer"
sendResponse:
@@ -144,7 +191,7 @@ actions:
- name: "X-Content-Type"
value: 'ct=application/json'
body:
- data: '[{"name": "Bob Jones", "city": "Rome"}]'
+ data: '[{"name": "Bob Jones", "city": "Rome", "_id": "2"}]'
- http:
server: "searchServer"
sendResponse:
@@ -176,3 +223,52 @@ actions:
status: 200
reasonPhrase: "OK"
version: "HTTP/1.1"
+
+ # queryDsl=false: a Query DSL text is searched for as words, so match_all
finds nothing
+ - http:
+ server: "searchServer"
+ receiveRequest:
+ POST:
+ path: "/words"
+ type: "json"
+ headers:
+ - name: "X-Body-Type"
+ value: 'java.lang.String'
+ - name: "X-Total-Hits"
+ value: '0'
+ - name: "X-Content-Type"
+ value: 'ct=application/json'
+ body:
+ data: '[]'
+ - http:
+ server: "searchServer"
+ sendResponse:
+ response:
+ status: 200
+ reasonPhrase: "OK"
+ version: "HTTP/1.1"
+
+ # a vector search: the place whose vector is closest, with only the fields
of _source; the total is not
+ # checked, as OpenSearch gives k hits for each segment of the index, here 2
+ - http:
+ server: "searchServer"
+ receiveRequest:
+ POST:
+ path: "/knn"
+ type: "json"
+ headers:
+ - name: "X-Body-Type"
+ value: 'java.lang.String'
+ - name: "X-Total-Hits"
+ value: '@ignore@'
+ - name: "X-Content-Type"
+ value: 'ct=application/json'
+ body:
+ data: '[{"name": "north", "_id": "n"}]'
+ - http:
+ server: "searchServer"
+ sendResponse:
+ response:
+ status: 200
+ reasonPhrase: "OK"
+ version: "HTTP/1.1"
diff --git
a/tests/camel-kamelets-itest/src/test/resources/opensearch/opensearch-search-action-route.yaml
b/tests/camel-kamelets-itest/src/test/resources/opensearch/opensearch-search-action-route.yaml
index c9d3c8172..023e109c9 100644
---
a/tests/camel-kamelets-itest/src/test/resources/opensearch/opensearch-search-action-route.yaml
+++
b/tests/camel-kamelets-itest/src/test/resources/opensearch/opensearch-search-action-route.yaml
@@ -92,3 +92,49 @@
simple: "ct=${header.Content-Type}"
- to:
uri: "{{http.sink.url}}/none"
+ # queryDsl=false: the body is words to search for, also when it is
Query DSL
+ - setBody:
+ constant: '{"match_all": {}}'
+ - to:
+ uri: "kamelet:opensearch-search-action"
+ parameters:
+ hostAddresses: '{{opensearch.host}}:{{opensearch.port}}'
+ clusterName: 'docker-cluster'
+ indexName: 'customers'
+ enableSSL: false
+ queryDsl: false
+ # what the Kamelet gives: the Java type of the body, the total and the
Content-Type
+ - setHeader:
+ name: X-Body-Type
+ simple: "${body.getClass().getName()}"
+ - setHeader:
+ name: X-Total-Hits
+ simple: "${header.CamelOpensearchTotalHits}"
+ - setHeader:
+ name: X-Content-Type
+ simple: "ct=${header.Content-Type}"
+ - to:
+ uri: "{{http.sink.url}}/words"
+ # a vector search in the Query DSL
+ - setBody:
+ constant: '{"query": {"knn": {"embedding": {"vector": [0.9, 0.1,
0.0], "k": 1}}}, "_source": ["name"]}'
+ - to:
+ uri: "kamelet:opensearch-search-action"
+ parameters:
+ hostAddresses: '{{opensearch.host}}:{{opensearch.port}}'
+ clusterName: 'docker-cluster'
+ indexName: 'places'
+ enableSSL: false
+ size: 1
+ # what the Kamelet gives: the Java type of the body, the total and the
Content-Type
+ - setHeader:
+ name: X-Body-Type
+ simple: "${body.getClass().getName()}"
+ - setHeader:
+ name: X-Total-Hits
+ simple: "${header.CamelOpensearchTotalHits}"
+ - setHeader:
+ name: X-Content-Type
+ simple: "ct=${header.Content-Type}"
+ - to:
+ uri: "{{http.sink.url}}/knn"