0

I am using the Elastic.Clients.Elasticsearch v8.19.11 client to connect to Elasticsearch. I want to validate a DSL query provided as a raw JSON string.

I'm not looking for simple JSON validation. Assuming the JSON is valid, I want to ensure the query structure itself is correct and will be understood by the connected Elasticsearch server.

The ElasticsearchClient.Indices API has a method ValidateQueryAsync which seems relevant, but I'm unsure how to use it with a raw DSL string.

One approach I considered is deserializing the DSL into a SearchRequest using:

using var ms = new MemoryStream(Encoding.UTF8.GetBytes(dsl));
var searchRequest = await elasticsearchClient.RequestResponseSerializer
    .DeserializeAsync<SearchRequest>(ms);

However, this only maps the JSON to a SearchRequest object and doesn't perform strict validation. I want to force validation so that if the query is invalid for the server, it will fail.

Question: How can I validate a raw DSL query string with Elastic.Clients.Elasticsearch to ensure it is syntactically correct and will be accepted by the Elasticsearch server?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.