Fix term(s) query for range field (#25918)

This commit is contained in:
Sam Cinco 2017-07-31 10:01:01 -04:00 committed by Adrien Grand
parent 7740cb54a5
commit e0359e7331
2 changed files with 20 additions and 1 deletions

View File

@ -283,7 +283,7 @@ public class RangeFieldMapper extends FieldMapper {
@Override
public Query termQuery(Object value, QueryShardContext context) {
Query query = rangeQuery(value, value, true, true, context);
Query query = rangeQuery(value, value, true, true, ShapeRelation.INTERSECTS, context);
if (boost() != 1f) {
query = new BoostQuery(query, boost());
}

View File

@ -276,4 +276,23 @@ public class RangeFieldTypeTests extends FieldTypeTestCase {
assertEquals(InetAddresses.forString("::1"), RangeFieldMapper.RangeType.IP.parse("::1", randomBoolean()));
assertEquals(InetAddresses.forString("::1"), RangeFieldMapper.RangeType.IP.parse(new BytesRef("::1"), randomBoolean()));
}
public void testTermQuery() throws Exception, IllegalArgumentException {
// See https://github.com/elastic/elasticsearch/issues/25950
Settings indexSettings = Settings.builder()
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build();
IndexSettings idxSettings = IndexSettingsModule.newIndexSettings(randomAlphaOfLengthBetween(1, 10), indexSettings);
QueryShardContext context = new QueryShardContext(0, idxSettings, null, null, null, null, null, xContentRegistry(),
writableRegistry(), null, null, () -> nowInMillis, null);
RangeFieldMapper.RangeFieldType ft = new RangeFieldMapper.RangeFieldType(type, Version.CURRENT);
ft.setName(FIELDNAME);
ft.setIndexOptions(IndexOptions.DOCS);
Object value = nextFrom();
ShapeRelation relation = ShapeRelation.INTERSECTS;
boolean includeLower = true;
boolean includeUpper = true;
assertEquals(getExpectedRangeQuery(relation, value, value, includeLower, includeUpper),
ft.termQuery(value, context));
}
}