The Elasticsearch Connector takes a QueryRequest
, which contains information about the query a user would like to run, translates it to an Elasticsearch DSL (Domain Specific Language) query, executes it against Elasticsearch, and returns the results as a QueryResponse
.
The connector has three main components:
- prepareElasticsearchQuery
- Search
- prepareResponse
Transforms QueryRequest
into Elasticsearch DSL (Domain Specific Language) queries.
Functionality:
- Parse the incoming
QueryRequest
. - Construct the DSL query with parameters like source, size, from, sort, and query.
API:
func prepareElasticsearchQuery(
ctx context.Context,
request *schema.QueryRequest,
state *types.State
) (map[string]interface{}, error)
Executes the DSL query against Elasticsearch and returns results.
Functionality:
- Execute queries on the specified Elasticsearch index.
- Fetch search results.
API:
func (e *Client) Search(
ctx context.Context,
index string,
body map[string]interface{}
) (map[string]interface{}, error)
Converts Elasticsearch search results into QueryResponse
.
Functionality:
- Traverse each field in the Elasticsearch response.
- Construct and return the QueryResponse, ensuring it conforms to the expected fields.
API:
func prepareResponse(
ctx context.Context,
response map[string]interface{}
) *schema.RowSet
-
Receive
QueryRequest
:- Incoming
QueryRequest
are intercepted by the connector.
- Incoming
-
Prepare Query:
- The
prepareElasticsearchQuery
component processes the incoming query, translating it into an Elasticsearch DSL query.
- The
-
Execute Query:
- The
Search
component executes the DSL query against Elasticsearch and retrieves the raw response.
- The
-
Prepare Response:
- The
prepareResponse
component transforms the raw Elasticsearch response into aQueryResponse
.
- The