Skip to content

Commit e1f844e

Browse files
committed
Mirror upstream elastic#137029 as single snapshot commit for AI review
BASE=4e68eccd9f663c2d4879f20c409444f3d7aa558b HEAD=d059b5f2d8e7790014d97a80fae570f96201c526 Branch=main
1 parent 4e68ecc commit e1f844e

File tree

4 files changed

+23
-58
lines changed

4 files changed

+23
-58
lines changed

server/src/main/java/org/elasticsearch/index/mapper/IpFieldMapper.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ private static IpFieldMapper toType(FieldMapper in) {
7474

7575
public static final class Builder extends FieldMapper.DimensionBuilder {
7676

77-
private final Parameter<Boolean> indexed = Parameter.indexParam(m -> toType(m).indexed, true);
77+
private final Parameter<Boolean> indexed;
7878
private final Parameter<Boolean> hasDocValues = Parameter.docValuesParam(m -> toType(m).hasDocValues, true);
7979
private final Parameter<Boolean> stored = Parameter.storeParam(m -> toType(m).stored, false);
8080

@@ -109,21 +109,16 @@ public Builder(
109109
this.indexCreatedVersion = indexCreatedVersion;
110110
this.ignoreMalformed = Parameter.boolParam("ignore_malformed", true, m -> toType(m).ignoreMalformed, ignoreMalformedByDefault);
111111
this.script.precludesParameters(nullValue, ignoreMalformed);
112-
addScriptValidation(script, indexed, hasDocValues);
113112
this.dimension = TimeSeriesParams.dimensionParam(m -> toType(m).dimension).addValidator(v -> {
114-
if (v && (indexed.getValue() == false || hasDocValues.getValue() == false)) {
113+
if (v && (hasDocValues.getValue() == false)) {
115114
throw new IllegalArgumentException(
116-
"Field ["
117-
+ TimeSeriesParams.TIME_SERIES_DIMENSION_PARAM
118-
+ "] requires that ["
119-
+ indexed.name
120-
+ "] and ["
121-
+ hasDocValues.name
122-
+ "] are true"
115+
"Field [" + TimeSeriesParams.TIME_SERIES_DIMENSION_PARAM + "] requires that [" + hasDocValues.name + "] is true"
123116
);
124117
}
125118
});
119+
this.indexed = Parameter.indexParam(m -> toType(m).indexed, () -> this.dimension.get() == false);
126120
this.indexSourceKeepMode = indexSourceKeepMode;
121+
addScriptValidation(script, indexed, hasDocValues);
127122
}
128123

129124
Builder nullValue(String nullValue) {
@@ -191,6 +186,9 @@ private IndexType indexType() {
191186
if (indexCreatedVersion.isLegacyIndexVersion()) {
192187
return hasDocValues.get() ? IndexType.archivedPoints() : IndexType.NONE;
193188
}
189+
if (dimension.get()) {
190+
return IndexType.skippers();
191+
}
194192
return IndexType.points(indexed.get(), hasDocValues.get());
195193
}
196194

@@ -660,7 +658,11 @@ private void indexValue(DocumentParserContext context, ESInetAddressPoint addres
660658
doc.add(address);
661659
}
662660
if (hasDocValues) {
663-
doc.add(new SortedSetDocValuesField(fieldType().name(), address.binaryValue()));
661+
if (indexed == false) {
662+
doc.add(SortedSetDocValuesField.indexedField(fieldType().name(), address.binaryValue()));
663+
} else {
664+
doc.add(new SortedSetDocValuesField(fieldType().name(), address.binaryValue()));
665+
}
664666
} else if (stored || indexed) {
665667
context.addToFieldNames(fieldType().name());
666668
}

server/src/main/java/org/elasticsearch/index/mapper/KeywordFieldMapper.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ private static KeywordFieldMapper toType(FieldMapper in) {
171171

172172
public static final class Builder extends FieldMapper.DimensionBuilder {
173173

174-
private final Parameter<Boolean> indexed = Parameter.indexParam(m -> toType(m).indexed, true);
174+
private final Parameter<Boolean> indexed;
175175
private final Parameter<Boolean> hasDocValues = Parameter.docValuesParam(m -> toType(m).hasDocValues, true);
176176
private final Parameter<Boolean> stored = Parameter.storeParam(m -> toType(m).fieldType.stored(), false);
177177

@@ -292,21 +292,16 @@ private Builder(
292292
);
293293

294294
this.script.precludesParameters(nullValue);
295-
addScriptValidation(script, indexed, hasDocValues);
296295

297296
this.dimension = TimeSeriesParams.dimensionParam(m -> toType(m).fieldType().isDimension()).addValidator(v -> {
298-
if (v && (indexed.getValue() == false || hasDocValues.getValue() == false)) {
297+
if (v && (hasDocValues.getValue() == false)) {
299298
throw new IllegalArgumentException(
300-
"Field ["
301-
+ TimeSeriesParams.TIME_SERIES_DIMENSION_PARAM
302-
+ "] requires that ["
303-
+ indexed.name
304-
+ "] and ["
305-
+ hasDocValues.name
306-
+ "] are true"
299+
"Field [" + TimeSeriesParams.TIME_SERIES_DIMENSION_PARAM + "] requires that [" + hasDocValues.name + "] is true"
307300
);
308301
}
309302
}).precludesParameters(normalizer);
303+
this.indexed = Parameter.indexParam(m -> toType(m).indexed, () -> this.dimension.get() == false);
304+
addScriptValidation(script, indexed, hasDocValues);
310305
this.ignoreAboveDefault = ignoreAboveDefault;
311306
this.ignoreAbove = Parameter.ignoreAboveParam(m -> toType(m).fieldType().ignoreAbove().get(), ignoreAboveDefault);
312307
this.indexSortConfig = indexSortConfig;
@@ -475,7 +470,7 @@ private KeywordFieldType buildFieldType(MapperBuilderContext context, FieldType
475470
public KeywordFieldMapper build(MapperBuilderContext context) {
476471
FieldType fieldtype = resolveFieldType(
477472
enableDocValuesSkipper,
478-
forceDocValuesSkipper,
473+
forceDocValuesSkipper || (this.dimension.get() && this.indexed.get() == false),
479474
hasDocValues,
480475
indexCreatedVersion,
481476
indexSortConfig,

server/src/test/java/org/elasticsearch/index/mapper/IpFieldMapperTests.java

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -232,30 +232,14 @@ public void testDimensionIndexedAndDocvalues() {
232232
minimalMapping(b);
233233
b.field("time_series_dimension", true).field("index", false).field("doc_values", false);
234234
})));
235-
assertThat(
236-
e.getCause().getMessage(),
237-
containsString("Field [time_series_dimension] requires that [index] and [doc_values] are true")
238-
);
235+
assertThat(e.getCause().getMessage(), containsString("Field [time_series_dimension] requires that [doc_values] is true"));
239236
}
240237
{
241238
Exception e = expectThrows(MapperParsingException.class, () -> createDocumentMapper(fieldMapping(b -> {
242239
minimalMapping(b);
243240
b.field("time_series_dimension", true).field("index", true).field("doc_values", false);
244241
})));
245-
assertThat(
246-
e.getCause().getMessage(),
247-
containsString("Field [time_series_dimension] requires that [index] and [doc_values] are true")
248-
);
249-
}
250-
{
251-
Exception e = expectThrows(MapperParsingException.class, () -> createDocumentMapper(fieldMapping(b -> {
252-
minimalMapping(b);
253-
b.field("time_series_dimension", true).field("index", false).field("doc_values", true);
254-
})));
255-
assertThat(
256-
e.getCause().getMessage(),
257-
containsString("Field [time_series_dimension] requires that [index] and [doc_values] are true")
258-
);
242+
assertThat(e.getCause().getMessage(), containsString("Field [time_series_dimension] requires that [doc_values] is true"));
259243
}
260244
}
261245

server/src/test/java/org/elasticsearch/index/mapper/KeywordFieldMapperTests.java

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -455,30 +455,14 @@ public void testDimensionIndexedAndDocvalues() {
455455
minimalMapping(b);
456456
b.field("time_series_dimension", true).field("index", false).field("doc_values", false);
457457
})));
458-
assertThat(
459-
e.getCause().getMessage(),
460-
containsString("Field [time_series_dimension] requires that [index] and [doc_values] are true")
461-
);
458+
assertThat(e.getCause().getMessage(), containsString("Field [time_series_dimension] requires that [doc_values] is true"));
462459
}
463460
{
464461
Exception e = expectThrows(MapperParsingException.class, () -> createDocumentMapper(fieldMapping(b -> {
465462
minimalMapping(b);
466463
b.field("time_series_dimension", true).field("index", true).field("doc_values", false);
467464
})));
468-
assertThat(
469-
e.getCause().getMessage(),
470-
containsString("Field [time_series_dimension] requires that [index] and [doc_values] are true")
471-
);
472-
}
473-
{
474-
Exception e = expectThrows(MapperParsingException.class, () -> createDocumentMapper(fieldMapping(b -> {
475-
minimalMapping(b);
476-
b.field("time_series_dimension", true).field("index", false).field("doc_values", true);
477-
})));
478-
assertThat(
479-
e.getCause().getMessage(),
480-
containsString("Field [time_series_dimension] requires that [index] and [doc_values] are true")
481-
);
465+
assertThat(e.getCause().getMessage(), containsString("Field [time_series_dimension] requires that [doc_values] is true"));
482466
}
483467
}
484468

0 commit comments

Comments
 (0)