How to validate a raw Elasticsearch DSL query string with Elastic.Clients.Elasticsearch v8?
10:01 13 Nov 2025

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(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?

elasticsearch elasticsearch-dsl elasticsearch-net