babsher
babsher

Reputation: 1016

Elasticsearch java validate api

I want to validate a query before saving it for use later. I see ES has a validate API but it cant see a way to use it with the Java api.

Is there a way to validate ES queries using the java api?

Maybe I could just run the query before saving it?

Upvotes: 6

Views: 883

Answers (1)

babsher
babsher

Reputation: 1016

So after looking at the elastic search source code I came up with this solution.

public ActionFuture<ValidateQueryResponse> validateAsync(QueryBuilder query, String[] indices) {
    final ValidateQueryRequest request = new ValidateQueryRequest();
    request.indices(indices);
    request.source(query.buildAsBytes());
    return esClient.admin().indices().validateQuery(request);
}

Upvotes: 2

Related Questions