Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 595
babsher Avatar asked Dec 16 '15 19:12

babsher


1 Answers

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);
}
like image 63
babsher Avatar answered Oct 12 '22 22:10

babsher