diff --git a/core/src/main/java/org/elasticsearch/index/mapper/RangeFieldMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/RangeFieldMapper.java index 067e47839c9..1f1cdd71e4b 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/RangeFieldMapper.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/RangeFieldMapper.java @@ -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()); } diff --git a/core/src/test/java/org/elasticsearch/index/mapper/RangeFieldTypeTests.java b/core/src/test/java/org/elasticsearch/index/mapper/RangeFieldTypeTests.java index 451e23eb954..328e61c2330 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/RangeFieldTypeTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/RangeFieldTypeTests.java @@ -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)); + } }