Fix RangeFieldMapper rangeQuery to properly handle relations
This commit fixes the RangeFieldMapper and RangeQueryBuilder to pass the correct relation to the RangeQuery when performing a range query over range fields.
This commit is contained in:
parent
c584c2fd71
commit
5ae48f7dd5
|
@ -282,12 +282,6 @@ public class RangeFieldMapper extends FieldMapper {
|
|||
return query;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper,
|
||||
QueryShardContext context) {
|
||||
return rangeQuery(lowerTerm, upperTerm, includeLower, includeUpper, ShapeRelation.INTERSECTS, context);
|
||||
}
|
||||
|
||||
public Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper,
|
||||
ShapeRelation relation, QueryShardContext context) {
|
||||
failIfNotIndexed();
|
||||
|
|
|
@ -495,9 +495,9 @@ public class RangeQueryBuilder extends AbstractQueryBuilder<RangeQueryBuilder> i
|
|||
|
||||
query = ((DateFieldMapper.DateFieldType) mapper).rangeQuery(from, to, includeLower, includeUpper,
|
||||
timeZone, getForceDateParser(), context);
|
||||
} else if (mapper instanceof RangeFieldMapper.RangeFieldType && mapper.typeName() == RangeFieldMapper.RangeType.DATE.name) {
|
||||
} else if (mapper instanceof RangeFieldMapper.RangeFieldType) {
|
||||
DateMathParser forcedDateParser = null;
|
||||
if (this.format != null) {
|
||||
if (mapper.typeName() == RangeFieldMapper.RangeType.DATE.name && this.format != null) {
|
||||
forcedDateParser = new DateMathParser(this.format);
|
||||
}
|
||||
query = ((RangeFieldMapper.RangeFieldType) mapper).rangeQuery(from, to, includeLower, includeUpper,
|
||||
|
|
|
@ -79,9 +79,6 @@ public class RangeQueryBuilderTests extends AbstractQueryTestCase<RangeQueryBuil
|
|||
query.format("yyyy-MM-dd'T'HH:mm:ss.SSSZZ");
|
||||
}
|
||||
}
|
||||
if (query.fieldName().equals(DATE_RANGE_FIELD_NAME)) {
|
||||
query.relation(RandomPicks.randomFrom(random(), ShapeRelation.values()).getRelationName());
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
default:
|
||||
|
@ -97,6 +94,9 @@ public class RangeQueryBuilderTests extends AbstractQueryTestCase<RangeQueryBuil
|
|||
if (randomBoolean()) {
|
||||
query.to(null);
|
||||
}
|
||||
if (query.fieldName().equals(INT_RANGE_FIELD_NAME) || query.fieldName().equals(DATE_RANGE_FIELD_NAME)) {
|
||||
query.relation(RandomPicks.randomFrom(random(), ShapeRelation.values()).getRelationName());
|
||||
}
|
||||
return query;
|
||||
}
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@ import org.elasticsearch.index.query.MatchQueryBuilder;
|
|||
import org.elasticsearch.index.query.MultiMatchQueryBuilder;
|
||||
import org.elasticsearch.index.query.Operator;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.index.query.RangeQueryBuilder;
|
||||
import org.elasticsearch.index.query.TermQueryBuilder;
|
||||
import org.elasticsearch.index.query.WrapperQueryBuilder;
|
||||
import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders;
|
||||
|
@ -1843,4 +1844,20 @@ public class SearchQueryIT extends ESIntegTestCase {
|
|||
assertThat(i + " expected: " + first + " actual: " + actual, Float.compare(first, actual), equalTo(0));
|
||||
}
|
||||
}
|
||||
|
||||
public void testRangeQueryRangeFields_24744() throws Exception {
|
||||
assertAcked(prepareCreate("test")
|
||||
.addMapping("type1", "int_range", "type=integer_range"));
|
||||
|
||||
client().prepareIndex("test", "type1", "1")
|
||||
.setSource(jsonBuilder()
|
||||
.startObject()
|
||||
.startObject("int_range").field("gte", 10).field("lte", 20).endObject()
|
||||
.endObject()).get();
|
||||
refresh();
|
||||
|
||||
RangeQueryBuilder range = new RangeQueryBuilder("int_range").relation("intersects").from(Integer.MIN_VALUE).to(Integer.MAX_VALUE);
|
||||
SearchResponse searchResponse = client().prepareSearch("test").setQuery(range).get();
|
||||
assertHitCount(searchResponse, 1);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue