### Question:
RegexEvaluator extends QueryEvaluator { @Override public boolean evaluate(QueryEvaluationContext ctx) { LOGGER.debug("evaluate {} {}", relativePath, regex); KeyValueCursor<Path, JsonNode> cursor = ctx.getNodes(relativePath); boolean ret = false; while (cursor.hasNext()) { cursor.next(); JsonNode valueNode = cursor.getCurrentValue(); Object docValue; if (valueNode != null) { docValue = fieldMd.getType().fromJson(valueNode); } else { docValue = null; } LOGGER.debug(" value={}", valueNode); if (docValue != null) { ret = regex.matcher(docValue.toString()).matches(); } if (ret) { break; } } ctx.setResult(ret); return ret; } RegexEvaluator(RegexMatchExpression expr, FieldTreeNode context); @Override boolean evaluate(QueryEvaluationContext ctx);  }### Answer:
@Test public void regex_on_field_partial_string_match_works() throws Exception { QueryExpression q = EvalTestContext.queryExpressionFromJson("{'field':'field1','regex':'val.*'}"); QueryEvaluator qe = QueryEvaluator.getInstance(q, md); QueryEvaluationContext ctx = qe.evaluate(jsonDoc); Assert.assertTrue(ctx.getResult()); }
@Test public void regex_on_field_partial_string_case_insensitive_match_works() throws Exception { QueryExpression q = EvalTestContext.queryExpressionFromJson("{'field':'field1','regex':'Val.*','caseInsensitive':1}"); QueryEvaluator qe = QueryEvaluator.getInstance(q, md); QueryEvaluationContext ctx = qe.evaluate(jsonDoc); ctx = qe.evaluate(jsonDoc); Assert.assertTrue(ctx.getResult()); }
@Test public void regex_expr_without_case_insensitive_returns_false() throws Exception { QueryExpression q = EvalTestContext.queryExpressionFromJson("{'field':'field1','regex':'Val.*'}"); QueryEvaluator qe = QueryEvaluator.getInstance(q, md); QueryEvaluationContext ctx = qe.evaluate(jsonDoc); ctx = qe.evaluate(jsonDoc); Assert.assertFalse(ctx.getResult()); }
@Test public void one_$parent_regex_on_field_partial_string_match_works() throws Exception { QueryExpression q = EvalTestContext.queryExpressionFromJson("{'field':'field2.$parent.field1','regex':'val.*'}"); QueryEvaluator qe = QueryEvaluator.getInstance(q, md); QueryEvaluationContext ctx = qe.evaluate(jsonDoc); Assert.assertTrue(ctx.getResult()); }
@Test public void one_$parent_regex_on_field_partial_string_case_insensitive_match_works() throws Exception { QueryExpression q = EvalTestContext.queryExpressionFromJson("{'field':'field2.$parent.field1','regex':'Val.*','caseInsensitive':1}"); QueryEvaluator qe = QueryEvaluator.getInstance(q, md); QueryEvaluationContext ctx = qe.evaluate(jsonDoc); ctx = qe.evaluate(jsonDoc); Assert.assertTrue(ctx.getResult()); }
@Test public void one_$parent_regex_expr_without_case_insensitive_returns_false() throws Exception { QueryExpression q = EvalTestContext.queryExpressionFromJson("{'field':'field2.$parent.field1','regex':'Val.*'}"); QueryEvaluator qe = QueryEvaluator.getInstance(q, md); QueryEvaluationContext ctx = qe.evaluate(jsonDoc); ctx = qe.evaluate(jsonDoc); Assert.assertFalse(ctx.getResult()); }