diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/SimpleIndexQueryParserTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/SimpleIndexQueryParserTests.java index 93858b7b8c8..78fe59cab88 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/SimpleIndexQueryParserTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/SimpleIndexQueryParserTests.java @@ -408,6 +408,17 @@ public class SimpleIndexQueryParserTests { assertThat(prefixQuery.getPrefix(), equalTo(new Term("name.first", "sh"))); } + @Test public void testPrefixBoostQuery() throws IOException { + IndexQueryParser queryParser = queryParser(); + String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/prefix-boost.json"); + Query parsedQuery = queryParser.parse(query).query(); + assertThat(parsedQuery, instanceOf(PrefixQuery.class)); + PrefixQuery prefixQuery = (PrefixQuery) parsedQuery; + // since age is automatically registered in data, we encode it as numeric + assertThat(prefixQuery.getPrefix(), equalTo(new Term("name.first", "sh"))); + assertThat((double) prefixQuery.getBoost(), closeTo(1.2, 0.00001)); + } + @Test public void testPrefixFilteredQueryBuilder() throws IOException { IndexQueryParser queryParser = queryParser(); Query parsedQuery = queryParser.parse(filteredQuery(termQuery("name.first", "shay"), prefixFilter("name.first", "sh"))).query(); @@ -474,6 +485,16 @@ public class SimpleIndexQueryParserTests { assertThat(wildcardQuery.getTerm(), equalTo(new Term("name.first", "sh*"))); } + @Test public void testWildcardBoostQuery() throws IOException { + IndexQueryParser queryParser = queryParser(); + String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/wildcard-boost.json"); + Query parsedQuery = queryParser.parse(query).query(); + assertThat(parsedQuery, instanceOf(WildcardQuery.class)); + WildcardQuery wildcardQuery = (WildcardQuery) parsedQuery; + assertThat(wildcardQuery.getTerm(), equalTo(new Term("name.first", "sh*"))); + assertThat((double) wildcardQuery.getBoost(), closeTo(1.2, 0.00001)); + } + @Test public void testRangeQueryBuilder() throws IOException { IndexQueryParser queryParser = queryParser(); Query parsedQuery = queryParser.parse(rangeQuery("age").from(23).to(54).includeLower(true).includeUpper(false)).query(); diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/prefix-boost.json b/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/prefix-boost.json new file mode 100644 index 00000000000..0e5e09d7c4d --- /dev/null +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/prefix-boost.json @@ -0,0 +1,8 @@ +{ + "prefix" : { + "name.first" : { + "value" : "sh", + "boost" : 1.2 + } + } +} \ No newline at end of file diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/wildcard-boost.json b/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/wildcard-boost.json new file mode 100644 index 00000000000..ba8a7c20800 --- /dev/null +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/wildcard-boost.json @@ -0,0 +1,8 @@ +{ + "wildcard" : { + "name.first" : { + "value" : "sh*", + "boost" : 1.2 + } + } +} \ No newline at end of file