diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/SpanTermQueryParser.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/SpanTermQueryParser.java index 14f642d7ea9..989455e0397 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/SpanTermQueryParser.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/SpanTermQueryParser.java @@ -74,6 +74,7 @@ public class SpanTermQueryParser implements QueryParser { } } } + parser.nextToken(); } else { value = parser.text(); // move to the next token diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/SimpleIndexQueryParserTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/SimpleIndexQueryParserTests.java index 10b617b54b8..1563038e73a 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/SimpleIndexQueryParserTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/SimpleIndexQueryParserTests.java @@ -1223,6 +1223,18 @@ public class SimpleIndexQueryParserTests { assertThat(((SpanTermQuery) spanOrQuery.getClauses()[2]).getTerm(), equalTo(new Term("age", NumericUtils.longToPrefixCoded(36)))); } + @Test public void testSpanOrQuery2() throws IOException { + IndexQueryParserService queryParser = queryParser(); + String query = copyToStringFromClasspath("/org/elasticsearch/index/query/spanOr2.json"); + Query parsedQuery = queryParser.parse(query).query(); + assertThat(parsedQuery, instanceOf(SpanOrQuery.class)); + SpanOrQuery spanOrQuery = (SpanOrQuery) parsedQuery; + assertThat(spanOrQuery.getClauses().length, equalTo(3)); + assertThat(((SpanTermQuery) spanOrQuery.getClauses()[0]).getTerm(), equalTo(new Term("age", NumericUtils.longToPrefixCoded(34)))); + assertThat(((SpanTermQuery) spanOrQuery.getClauses()[1]).getTerm(), equalTo(new Term("age", NumericUtils.longToPrefixCoded(35)))); + assertThat(((SpanTermQuery) spanOrQuery.getClauses()[2]).getTerm(), equalTo(new Term("age", NumericUtils.longToPrefixCoded(36)))); + } + @Test public void testQueryFilterBuilder() throws Exception { IndexQueryParserService queryParser = queryParser(); Query parsedQuery = queryParser.parse(filteredQuery(termQuery("name.first", "shay"), queryFilter(termQuery("name.last", "banon")))).query(); diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/spanOr2.json b/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/spanOr2.json new file mode 100644 index 00000000000..e323898ace5 --- /dev/null +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/spanOr2.json @@ -0,0 +1,30 @@ +{ + "span_or" : { + "clauses" : [ + { + "span_term" : { + "age" : { + "value" : 34, + "boost" : 1.0 + } + } + }, + { + "span_term" : { + "age" : { + "value" : 35, + "boost" : 1.0 + } + } + }, + { + "span_term" : { + "age" : { + "value" : 36, + "boost" : 1.0 + } + } + } + ] + } +} \ No newline at end of file