fix range query rewrite so it rewrites correctly when shard min value == shard max value
This commit is contained in:
parent
c62eff0ac9
commit
d17fd335e4
|
@ -265,7 +265,7 @@ public class RangeQueryBuilder extends AbstractQueryBuilder<RangeQueryBuilder> i
|
|||
// rewrite so just return without rewriting
|
||||
if (fieldStatsProvider != null) {
|
||||
DateMathParser dateMathParser = format == null ? null : new DateMathParser(format);
|
||||
FieldStatsProvider.Relation relation = fieldStatsProvider.isFieldWithinQuery(fieldName, from, to, includeUpper, includeLower,
|
||||
FieldStatsProvider.Relation relation = fieldStatsProvider.isFieldWithinQuery(fieldName, from, to, includeLower, includeUpper,
|
||||
timeZone, dateMathParser);
|
||||
switch (relation) {
|
||||
case DISJOINT:
|
||||
|
@ -278,15 +278,10 @@ public class RangeQueryBuilder extends AbstractQueryBuilder<RangeQueryBuilder> i
|
|||
// bound has not been changed by the rewrite
|
||||
RangeQueryBuilder newRangeQuery = new RangeQueryBuilder(fieldName);
|
||||
String dateFormatString = format == null ? null : format.format();
|
||||
if (fieldStats.getMinValue().equals(fieldStats.getMaxValue())) {
|
||||
newRangeQuery.from(fieldStats.getMinValue(), true);
|
||||
newRangeQuery.to(fieldStats.getMaxValue(), true);
|
||||
} else {
|
||||
newRangeQuery.from(fieldStats.getMinValue(), includeLower || fieldStats.match(new IndexConstraint(fieldName,
|
||||
Property.MIN, Comparison.GT, fieldStats.stringValueOf(from, dateFormatString))));
|
||||
newRangeQuery.to(fieldStats.getMaxValue(), includeUpper || fieldStats.match(new IndexConstraint(fieldName,
|
||||
Property.MAX, Comparison.LT, fieldStats.stringValueOf(to, dateFormatString))));
|
||||
}
|
||||
newRangeQuery.from(fieldStats.getMinValue(), includeLower || fieldStats.match(
|
||||
new IndexConstraint(fieldName, Property.MIN, Comparison.GT, fieldStats.stringValueOf(from, dateFormatString))));
|
||||
newRangeQuery.to(fieldStats.getMaxValue(), includeUpper || fieldStats.match(
|
||||
new IndexConstraint(fieldName, Property.MAX, Comparison.LT, fieldStats.stringValueOf(to, dateFormatString))));
|
||||
newRangeQuery.format = format;
|
||||
newRangeQuery.timeZone = timeZone;
|
||||
return newRangeQuery;
|
||||
|
|
|
@ -53,15 +53,17 @@ public class MatchedQueriesIT extends ESIntegTestCase {
|
|||
refresh();
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch()
|
||||
.setQuery(boolQuery().must(matchAllQuery()).filter(boolQuery().should(rangeQuery("number").lte(2).queryName("test1")).should(rangeQuery("number").gt(2).queryName("test2")))).get();
|
||||
.setQuery(boolQuery().must(matchAllQuery()).filter(boolQuery()
|
||||
.should(rangeQuery("number").lt(2).queryName("test1")).should(rangeQuery("number").gte(2).queryName("test2"))))
|
||||
.get();
|
||||
assertHitCount(searchResponse, 3L);
|
||||
for (SearchHit hit : searchResponse.getHits()) {
|
||||
if (hit.id().equals("1") || hit.id().equals("2")) {
|
||||
assertThat(hit.matchedQueries().length, equalTo(1));
|
||||
assertThat(hit.matchedQueries(), hasItemInArray("test1"));
|
||||
} else if (hit.id().equals("3")) {
|
||||
if (hit.id().equals("3") || hit.id().equals("2")) {
|
||||
assertThat(hit.matchedQueries().length, equalTo(1));
|
||||
assertThat(hit.matchedQueries(), hasItemInArray("test2"));
|
||||
} else if (hit.id().equals("1")) {
|
||||
assertThat(hit.matchedQueries().length, equalTo(1));
|
||||
assertThat(hit.matchedQueries(), hasItemInArray("test1"));
|
||||
} else {
|
||||
fail("Unexpected document returned with id " + hit.id());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue