Skip to content

Commit 5367285

Browse files
feat(sources/elasticsearch): add Elasticsearch source and tools (googleapis#1109)
Add support for Elasticsearch with the following tools: * search * esql * get_mappings * list_indices This PR fixes googleapis#859 --------- Co-authored-by: duwenxin <[email protected]> Co-authored-by: Wenxin Du <[email protected]>
1 parent d7f68eb commit 5367285

File tree

16 files changed

+1227
-3
lines changed

16 files changed

+1227
-3
lines changed

.ci/integration.cloudbuild.yaml

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,26 @@ steps:
705705
- |
706706
./yugabytedb.test -test.v
707707
708-
708+
- id: "elasticsearch"
709+
name: golang:1
710+
waitFor: ["compile-test-binary"]
711+
entrypoint: /bin/bash
712+
env:
713+
- "GOPATH=/gopath"
714+
- "SERVICE_ACCOUNT_EMAIL=$SERVICE_ACCOUNT_EMAIL"
715+
secretEnv: ["CLIENT_ID", "ELASTICSEARCH_USER", "ELASTICSEARCH_PASS", "ELASTICSEARCH_HOST"]
716+
volumes:
717+
- name: "go"
718+
path: "/gopath"
719+
args:
720+
- -c
721+
- |
722+
.ci/test_with_coverage.sh \
723+
"Elasticsearch" \
724+
elasticsearch \
725+
elasticsearch
726+
727+
709728
- id: "cassandra"
710729
name: golang:1
711730
waitFor: ["compile-test-binary"]
@@ -764,7 +783,7 @@ steps:
764783
.ci/test_with_coverage.sh \
765784
"Serverless Spark" \
766785
serverlessspark
767-
786+
768787
availableSecrets:
769788
secretManager:
770789
- versionName: projects/$PROJECT_ID/secrets/cloud_sql_pg_user/versions/latest
@@ -855,6 +874,12 @@ availableSecrets:
855874
env: YUGABYTEDB_USER
856875
- versionName: projects/$PROJECT_ID/secrets/yugabytedb_pass/versions/latest
857876
env: YUGABYTEDB_PASS
877+
- versionName: projects/$PROJECT_ID/secrets/elastic_search_host/versions/latest
878+
env: ELASTICSEARCH_HOST
879+
- versionName: projects/$PROJECT_ID/secrets/elastic_search_user/versions/latest
880+
env: ELASTICSEARCH_USER
881+
- versionName: projects/$PROJECT_ID/secrets/elastic_search_pass/versions/latest
882+
env: ELASTICSEARCH_PASS
858883
- versionName: projects/$PROJECT_ID/secrets/cassandra_user/versions/latest
859884
env: CASSANDRA_USER
860885
- versionName: projects/$PROJECT_ID/secrets/cassandra_pass/versions/latest

cmd/root.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ import (
8585
_ "github.com/googleapis/genai-toolbox/internal/tools/dataplex/dataplexsearchaspecttypes"
8686
_ "github.com/googleapis/genai-toolbox/internal/tools/dataplex/dataplexsearchentries"
8787
_ "github.com/googleapis/genai-toolbox/internal/tools/dgraph"
88+
_ "github.com/googleapis/genai-toolbox/internal/tools/elasticsearch/elasticsearchesql"
8889
_ "github.com/googleapis/genai-toolbox/internal/tools/firebird/firebirdexecutesql"
8990
_ "github.com/googleapis/genai-toolbox/internal/tools/firebird/firebirdsql"
9091
_ "github.com/googleapis/genai-toolbox/internal/tools/firestore/firestoreadddocuments"
@@ -195,6 +196,7 @@ import (
195196
_ "github.com/googleapis/genai-toolbox/internal/sources/couchbase"
196197
_ "github.com/googleapis/genai-toolbox/internal/sources/dataplex"
197198
_ "github.com/googleapis/genai-toolbox/internal/sources/dgraph"
199+
_ "github.com/googleapis/genai-toolbox/internal/sources/elasticsearch"
198200
_ "github.com/googleapis/genai-toolbox/internal/sources/firebird"
199201
_ "github.com/googleapis/genai-toolbox/internal/sources/firestore"
200202
_ "github.com/googleapis/genai-toolbox/internal/sources/http"
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
title: "Elasticsearch"
3+
type: docs
4+
weight: 1
5+
description: >
6+
Elasticsearch is a distributed, free and open search and analytics engine
7+
for all types of data, including textual, numerical, geospatial, structured,
8+
and unstructured.
9+
---
10+
11+
# Elasticsearch Source
12+
13+
[Elasticsearch][elasticsearch-docs] is a distributed, free and open search and analytics engine
14+
for all types of data, including textual, numerical, geospatial, structured,
15+
and unstructured.
16+
17+
If you are new to Elasticsearch, you can learn how to
18+
[set up a cluster and start indexing data][elasticsearch-quickstart].
19+
20+
Elasticsearch uses [ES|QL][elasticsearch-esql] for querying data. ES|QL
21+
is a powerful query language that allows you to search and aggregate data in
22+
Elasticsearch.
23+
24+
See the [official documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html) for more information.
25+
26+
[elasticsearch-docs]: https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html
27+
[elasticsearch-quickstart]: https://www.elastic.co/guide/en/elasticsearch/reference/current/getting-started.html
28+
[elasticsearch-esql]: https://www.elastic.co/guide/en/elasticsearch/reference/current/esql.html
29+
30+
## Available Tools
31+
32+
- [`elasticsearch-esql`](../tools/elasticsearch/elasticsearch-esql.md)
33+
Execute ES|QL queries.
34+
35+
## Requirements
36+
37+
### API Key
38+
39+
Toolbox uses an [API key][api-key] to authorize and authenticate when
40+
interacting with [Elasticsearch][elasticsearch-docs].
41+
42+
In addition to [setting the API key for your server][set-api-key], you need to
43+
ensure the API key has the correct permissions for the queries you intend to
44+
run. See [API key management][api-key-management] for more information on
45+
applying permissions to an API key.
46+
47+
[api-key]: https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-create-api-key.html
48+
[set-api-key]: https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-create-api-key.html
49+
[api-key-management]: https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-get-api-key.html
50+
51+
## Example
52+
53+
```yaml
54+
sources:
55+
my-elasticsearch-source:
56+
kind: "elasticsearch"
57+
addresses:
58+
- "http://localhost:9200"
59+
apikey: "my-api-key"
60+
```
61+
62+
## Reference
63+
64+
| **field** | **type** | **required** | **description** |
65+
|-----------|:--------:|:------------:|-------------------------------------------------------------------------------|
66+
| kind | string | true | Must be "elasticsearch". |
67+
| addresses | []string | true | List of Elasticsearch hosts to connect to. |
68+
| apikey | string | true | The API key to use for authentication. |
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
title: "Elasticsearch"
3+
type: docs
4+
weight: 1
5+
description: >
6+
Tools that work with Elasticsearch Sources.
7+
---
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
title: "elasticsearch-esql"
3+
type: docs
4+
weight: 2
5+
description: >
6+
Execute ES|QL queries.
7+
---
8+
9+
# elasticsearch-esql
10+
11+
Execute ES|QL queries.
12+
13+
This tool allows you to execute ES|QL queries against your Elasticsearch
14+
cluster. You can use this to perform complex searches and aggregations.
15+
16+
See the [official documentation](https://www.elastic.co/docs/reference/query-languages/esql/esql-getting-started) for more information.
17+
18+
## Example
19+
20+
```yaml
21+
tools:
22+
query_my_index:
23+
kind: elasticsearch-esql
24+
source: elasticsearch-source
25+
description: Use this tool to execute ES|QL queries.
26+
query: |
27+
FROM my-index
28+
| KEEP *
29+
| LIMIT ?limit
30+
parameters:
31+
- name: limit
32+
type: integer
33+
description: Limit the number of results.
34+
required: true
35+
```
36+
37+
## Parameters
38+
39+
| **name** | **type** | **required** | **description** |
40+
|------------|:--------:|:------------:|-----------------------------------------------------------------------------------------------------------------------------------------------------|
41+
| query | string | false | The ES\|QL query to run. Can also be passed by parameters. |
42+
| format | string | false | The format of the query. Default is json. Valid values are csv, json, tsv, txt, yaml, cbor, smile, or arrow. |
43+
| timeout | integer | false | The timeout for the query in seconds. Default is 60 (1 minute). |
44+
| parameters | [parameters](../#specifying-parameters) | false | List of [parameters](../#specifying-parameters) that will be used with the ES\|QL query.<br/>Only supports “string”, “integer”, “float”, “boolean”. |
45+

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ require (
2121
github.com/cenkalti/backoff/v5 v5.0.3
2222
github.com/couchbase/gocb/v2 v2.11.1
2323
github.com/couchbase/tools-common/http v1.0.9
24+
github.com/elastic/elastic-transport-go/v8 v8.7.0
25+
github.com/elastic/go-elasticsearch/v8 v8.19.0
2426
github.com/fsnotify/fsnotify v1.9.0
2527
github.com/go-chi/chi/v5 v5.2.3
2628
github.com/go-chi/httplog/v2 v2.1.1

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,10 @@ github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3
820820
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
821821
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
822822
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
823+
github.com/elastic/elastic-transport-go/v8 v8.7.0 h1:OgTneVuXP2uip4BA658Xi6Hfw+PeIOod2rY3GVMGoVE=
824+
github.com/elastic/elastic-transport-go/v8 v8.7.0/go.mod h1:YLHer5cj0csTzNFXoNQ8qhtGY1GTvSqPnKWKaqQE3Hk=
825+
github.com/elastic/go-elasticsearch/v8 v8.19.0 h1:VmfBLNRORY7RZL+9hTxBD97ehl9H8Nxf2QigDh6HuMU=
826+
github.com/elastic/go-elasticsearch/v8 v8.19.0/go.mod h1:F3j9e+BubmKvzvLjNui/1++nJuJxbkhHefbaT0kFKGY=
823827
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
824828
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
825829
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=

internal/prebuiltconfigs/prebuiltconfigs_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ var expectedToolSources = []string{
3636
"cloud-sql-postgres-observability",
3737
"cloud-sql-postgres",
3838
"dataplex",
39+
"elasticsearch",
3940
"firestore",
4041
"looker-conversational-analytics",
4142
"looker",
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
sources:
16+
elasticsearch-source:
17+
kind: elasticsearch
18+
addresses:
19+
- ${ELASTICSEARCH_HOST}
20+
apikey: ${ELASTICSEARCH_APIKEY}
21+
22+
tools:
23+
execute_esql_query:
24+
kind: elasticsearch-esql
25+
source: elasticsearch-source
26+
description: Use this tool to execute ES|QL queries.
27+
parameters:
28+
- name: query
29+
type: string
30+
description: The ES|QL query to execute.
31+
toolsets:
32+
elasticsearch-tools:
33+
- execute_esql_query

0 commit comments

Comments
 (0)