6

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?

1
  • > IF you use java for elastic-search, why not you use java-driver of elacticsearch and query by querybuilder : Query Builder Commented Dec 16, 2015 at 21:27

1 Answer 1

2

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);
}
Sign up to request clarification or add additional context in comments.

Comments

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.