|
34 | 34 | import org.elasticsearch.Version;
|
35 | 35 | import org.elasticsearch.cluster.metadata.IndexMetaData;
|
36 | 36 | import org.elasticsearch.common.geo.ShapeRelation;
|
| 37 | +import org.elasticsearch.common.joda.DateMathParser; |
| 38 | +import org.elasticsearch.common.joda.FormatDateTimeFormatter; |
37 | 39 | import org.elasticsearch.common.joda.Joda;
|
38 | 40 | import org.elasticsearch.common.network.InetAddresses;
|
39 | 41 | import org.elasticsearch.common.settings.Settings;
|
@@ -98,6 +100,33 @@ public void testRangeQuery() throws Exception {
|
98 | 100 | ft.rangeQuery(from, to, includeLower, includeUpper, relation, null, null, context));
|
99 | 101 | }
|
100 | 102 |
|
| 103 | + public void testRangeQueryUsingMappingFormat() throws Exception { |
| 104 | + Settings indexSettings = Settings.builder() |
| 105 | + .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(); |
| 106 | + IndexSettings idxSettings = IndexSettingsModule.newIndexSettings(randomAlphaOfLengthBetween(1, 10), indexSettings); |
| 107 | + QueryShardContext context = new QueryShardContext(0, idxSettings, null, null, null, null, null, xContentRegistry(), |
| 108 | + writableRegistry(), null, null, () -> nowInMillis, null); |
| 109 | + |
| 110 | + Version version = randomFrom(Version.V_5_0_0_alpha1, Version.V_6_0_0_beta1, Version.CURRENT); |
| 111 | + RangeFieldMapper.RangeFieldType ft = new RangeFieldMapper.RangeFieldType(RangeType.DATE, version); |
| 112 | + ft.setName(FIELDNAME); |
| 113 | + ft.setIndexOptions(IndexOptions.DOCS); |
| 114 | + |
| 115 | + FormatDateTimeFormatter formatter = Joda.forPattern( "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"); |
| 116 | + ft.setDateTimeFormatter(formatter); |
| 117 | + ShapeRelation relation = RandomPicks.randomFrom(random(), ShapeRelation.values()); |
| 118 | + boolean includeLower = random().nextBoolean(); |
| 119 | + boolean includeUpper = random().nextBoolean(); |
| 120 | + Object from = nextFrom(); |
| 121 | + Object to = nextTo(from); |
| 122 | + |
| 123 | + boolean hasDocValues = version.onOrAfter(Version.V_6_0_0_beta1); |
| 124 | + assertEquals( |
| 125 | + RangeType.DATE.rangeQuery(FIELDNAME, hasDocValues, from, to, includeLower, |
| 126 | + includeUpper, relation, null, ft.dateMathParser(), context), |
| 127 | + ft.rangeQuery(from, to, includeLower, includeUpper, relation, null, ft.dateMathParser(), context)); |
| 128 | + } |
| 129 | + |
101 | 130 | private Query getExpectedRangeQuery(ShapeRelation relation, Object from, Object to, boolean includeLower, boolean includeUpper) {
|
102 | 131 | switch (type) {
|
103 | 132 | case DATE:
|
|
0 commit comments