diff --git a/src/main/java/org/elasticsearch/indices/query/IndicesQueriesModule.java b/src/main/java/org/elasticsearch/indices/query/IndicesQueriesModule.java index e71b7f2c73c..2a67a872bcb 100644 --- a/src/main/java/org/elasticsearch/indices/query/IndicesQueriesModule.java +++ b/src/main/java/org/elasticsearch/indices/query/IndicesQueriesModule.java @@ -92,6 +92,7 @@ public class IndicesQueriesModule extends AbstractModule { qpBinders.addBinding().to(CustomFiltersScoreQueryParser.class).asEagerSingleton(); qpBinders.addBinding().to(SpanTermQueryParser.class).asEagerSingleton(); qpBinders.addBinding().to(SpanNotQueryParser.class).asEagerSingleton(); + qpBinders.addBinding().to(FieldMaskingSpanQueryParser.class).asEagerSingleton(); qpBinders.addBinding().to(SpanFirstQueryParser.class).asEagerSingleton(); qpBinders.addBinding().to(SpanNearQueryParser.class).asEagerSingleton(); qpBinders.addBinding().to(SpanOrQueryParser.class).asEagerSingleton(); diff --git a/src/test/java/org/elasticsearch/test/unit/index/query/SimpleIndexQueryParserTests.java b/src/test/java/org/elasticsearch/test/unit/index/query/SimpleIndexQueryParserTests.java index 10b04cfddce..81c5e3f934e 100644 --- a/src/test/java/org/elasticsearch/test/unit/index/query/SimpleIndexQueryParserTests.java +++ b/src/test/java/org/elasticsearch/test/unit/index/query/SimpleIndexQueryParserTests.java @@ -1538,6 +1538,22 @@ public class SimpleIndexQueryParserTests { assertThat(((SpanTermQuery) spanNearQuery.getClauses()[2]).getTerm(), equalTo(new Term("age", longToPrefixCoded(36, 0)))); assertThat(spanNearQuery.isInOrder(), equalTo(false)); } + + @Test + public void testFieldMaskingSpanQuery() throws IOException { + IndexQueryParserService queryParser = queryParser(); + String query = copyToStringFromClasspath("/org/elasticsearch/test/unit/index/query/spanFieldMaskingTerm.json"); + Query parsedQuery = queryParser.parse(query).query(); + assertThat(parsedQuery, instanceOf(SpanNearQuery.class)); + SpanNearQuery spanNearQuery = (SpanNearQuery) parsedQuery; + assertThat(spanNearQuery.getClauses().length, equalTo(3)); + assertThat(((SpanTermQuery) spanNearQuery.getClauses()[0]).getTerm(), equalTo(new Term("age", longToPrefixCoded(34, 0)))); + assertThat(((SpanTermQuery) spanNearQuery.getClauses()[1]).getTerm(), equalTo(new Term("age", longToPrefixCoded(35, 0)))); + assertThat(((SpanTermQuery)((FieldMaskingSpanQuery) spanNearQuery.getClauses()[2]).getMaskedQuery()).getTerm(), equalTo(new Term("age_1", "36"))); + assertThat(spanNearQuery.isInOrder(), equalTo(false)); + } + + @Test public void testSpanOrQueryBuilder() throws IOException { diff --git a/src/test/java/org/elasticsearch/test/unit/index/query/spanFieldMaskingTerm.json b/src/test/java/org/elasticsearch/test/unit/index/query/spanFieldMaskingTerm.json new file mode 100644 index 00000000000..9849c105e9a --- /dev/null +++ b/src/test/java/org/elasticsearch/test/unit/index/query/spanFieldMaskingTerm.json @@ -0,0 +1,29 @@ +{ + span_near:{ + clauses:[ + { + span_term:{ + age:34 + } + }, + { + span_term:{ + age:35 + } + }, + { + field_masking_span:{ + query:{ + span_term:{ + age_1 : 36 + } + }, + field:"age" + } + } + ], + slop:12, + in_order:false, + collect_payloads:false + } +} \ No newline at end of file