/**
  * Fails if a percolator contains an unsupported query. The following queries are not supported:
  * 1) a range query with a date range based on current time 2) a has_child query 3) a has_parent
  * query
  */
 static void verifyQuery(QueryBuilder queryBuilder) {
   if (queryBuilder instanceof RangeQueryBuilder) {
     RangeQueryBuilder rangeQueryBuilder = (RangeQueryBuilder) queryBuilder;
     if (rangeQueryBuilder.from() instanceof String) {
       String from = (String) rangeQueryBuilder.from();
       String to = (String) rangeQueryBuilder.to();
       if (from.contains("now") || to.contains("now")) {
         throw new IllegalArgumentException(
             "percolator queries containing time range queries based on the "
                 + "current time is unsupported");
       }
     }
   } else if (queryBuilder instanceof HasChildQueryBuilder) {
     throw new IllegalArgumentException(
         "the [has_child] query is unsupported inside a percolator query");
   } else if (queryBuilder instanceof HasParentQueryBuilder) {
     throw new IllegalArgumentException(
         "the [has_parent] query is unsupported inside a percolator query");
   } else if (queryBuilder instanceof BoolQueryBuilder) {
     BoolQueryBuilder boolQueryBuilder = (BoolQueryBuilder) queryBuilder;
     List<QueryBuilder> clauses = new ArrayList<>();
     clauses.addAll(boolQueryBuilder.filter());
     clauses.addAll(boolQueryBuilder.must());
     clauses.addAll(boolQueryBuilder.mustNot());
     clauses.addAll(boolQueryBuilder.should());
     for (QueryBuilder clause : clauses) {
       verifyQuery(clause);
     }
   } else if (queryBuilder instanceof ConstantScoreQueryBuilder) {
     verifyQuery(((ConstantScoreQueryBuilder) queryBuilder).innerQuery());
   } else if (queryBuilder instanceof FunctionScoreQueryBuilder) {
     verifyQuery(((FunctionScoreQueryBuilder) queryBuilder).query());
   } else if (queryBuilder instanceof BoostingQueryBuilder) {
     verifyQuery(((BoostingQueryBuilder) queryBuilder).negativeQuery());
     verifyQuery(((BoostingQueryBuilder) queryBuilder).positiveQuery());
   }
 }