Skip to content

Commit f7f96d6

Browse files
jordan-powerselasticsearchmachine
andauthored
[8.19] Fix dropped ignore above fields (elastic#137394) (elastic#137415)
* Fix dropped ignore above fields (elastic#137394) Currently, the CompositeSyntheticFieldLoaders for the various text-family field mappers only load the stored fields containing the original non-ignored values if ignore_above is set to a non-default value. But if a value is ignored due to hitting a default ignore_above limit, it won't be loaded by the field loader. This PR corrects that logic. Fixes elastic#137360. Co-authored-by: Felix Barnsteiner <[email protected]> (cherry picked from commit 61025ff) # Conflicts: # modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/extras/MatchOnlyTextFieldMapper.java # server/src/main/java/org/elasticsearch/index/mapper/KeywordFieldMapper.java # server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java * [CI] Auto commit changes from spotless --------- Co-authored-by: elasticsearchmachine <[email protected]>
1 parent 9a2e869 commit f7f96d6

File tree

9 files changed

+218
-8
lines changed

9 files changed

+218
-8
lines changed

docs/changelog/137394.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 137394
2+
summary: Fix dropped ignore above fields
3+
area: Mapping
4+
type: bug
5+
issues:
6+
- 137360

modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/extras/MatchOnlyTextFieldMapper.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,8 @@ private IOFunction<LeafReaderContext, CheckedIntFunction<List<Object>, IOExcepti
247247
String parentField = searchExecutionContext.parentPath(name());
248248
var parent = searchExecutionContext.lookup().fieldType(parentField);
249249

250-
if (parent instanceof KeywordFieldMapper.KeywordFieldType keywordParent && keywordParent.ignoreAbove().isSet()) {
250+
if (parent instanceof KeywordFieldMapper.KeywordFieldType keywordParent
251+
&& keywordParent.ignoreAbove().valuesPotentiallyIgnored()) {
251252
if (parent.isStored()) {
252253
return storedFieldFetcher(parentField, keywordParent.originalName());
253254
} else if (parent.hasDocValues()) {
@@ -268,7 +269,7 @@ private IOFunction<LeafReaderContext, CheckedIntFunction<List<Object>, IOExcepti
268269
var kwd = textFieldType.syntheticSourceDelegate();
269270

270271
if (kwd != null) {
271-
if (kwd.ignoreAbove().isSet()) {
272+
if (kwd.ignoreAbove().valuesPotentiallyIgnored()) {
272273
if (kwd.isStored()) {
273274
return storedFieldFetcher(kwd.name(), kwd.originalName());
274275
} else if (kwd.hasDocValues()) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1240,7 +1240,7 @@ protected BytesRef preserve(BytesRef value) {
12401240
}
12411241
}
12421242

1243-
if (fieldType().ignoreAbove.isSet()) {
1243+
if (fieldType().ignoreAbove.valuesPotentiallyIgnored()) {
12441244
layers.add(new CompositeSyntheticFieldLoader.StoredFieldLayer(originalName) {
12451245
@Override
12461246
protected void writeValue(Object value, XContentBuilder b) throws IOException {

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ default boolean supportsVersion(IndexVersion indexCreatedVersion) {
139139
* This class models the ignore_above parameter in indices.
140140
*/
141141
public static final class IgnoreAbove {
142-
142+
// We use Integer.MAX_VALUE to represent a no-op, accepting all values.
143143
public static final int IGNORE_ABOVE_DEFAULT_VALUE = Integer.MAX_VALUE;
144144
public static final int IGNORE_ABOVE_DEFAULT_VALUE_FOR_LOGSDB_INDICES = 8191;
145145

@@ -175,6 +175,15 @@ public boolean isSet() {
175175
return Integer.valueOf(get()).equals(defaultValue) == false;
176176
}
177177

178+
/**
179+
* Returns whether values are potentially ignored, either by an explicitly configured ignore_above or by the default value.
180+
*/
181+
public boolean valuesPotentiallyIgnored() {
182+
// We use Integer.MAX_VALUE to represent accepting all values. If the value is anything else, then either we have an
183+
// explicitly configured ignore_above, or we have a non no-op default.
184+
return get() != Integer.MAX_VALUE;
185+
}
186+
178187
/**
179188
* Returns whether the given string will be ignored.
180189
*/

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,15 +1012,15 @@ public boolean isAggregatable() {
10121012
* A delegate by definition must have doc_values or be stored so most of the time it can be used for loading.
10131013
*/
10141014
public boolean canUseSyntheticSourceDelegateForLoading() {
1015-
return syntheticSourceDelegate != null && syntheticSourceDelegate.ignoreAbove().isSet() == false;
1015+
return syntheticSourceDelegate != null && syntheticSourceDelegate.ignoreAbove().valuesPotentiallyIgnored() == false;
10161016
}
10171017

10181018
/**
10191019
* Returns true if the delegate sub-field can be used for querying only (ie. isIndexed must be true)
10201020
*/
10211021
public boolean canUseSyntheticSourceDelegateForQuerying() {
10221022
return syntheticSourceDelegate != null
1023-
&& syntheticSourceDelegate.ignoreAbove().isSet() == false
1023+
&& syntheticSourceDelegate.ignoreAbove().valuesPotentiallyIgnored() == false
10241024
&& syntheticSourceDelegate.isIndexed();
10251025
}
10261026

server/src/main/java/org/elasticsearch/index/mapper/flattened/FlattenedFieldMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ protected SyntheticSourceSupport syntheticSourceSupport() {
925925
() -> new FlattenedSortedSetDocValuesSyntheticFieldLoader(
926926
fullPath(),
927927
fullPath() + KEYED_FIELD_SUFFIX,
928-
fieldType().ignoreAbove.isSet() ? fullPath() + KEYED_IGNORED_VALUES_FIELD_SUFFIX : null,
928+
fieldType().ignoreAbove.valuesPotentiallyIgnored() ? fullPath() + KEYED_IGNORED_VALUES_FIELD_SUFFIX : null,
929929
leafName()
930930
)
931931
);

server/src/test/java/org/elasticsearch/index/IgnoreAboveTests.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public void test_ignore_above_with_value_and_index_mode_and_index_version() {
2525
// when/then
2626
assertEquals(123, ignoreAbove.get());
2727
assertTrue(ignoreAbove.isSet());
28+
assertTrue(ignoreAbove.valuesPotentiallyIgnored());
2829
}
2930

3031
public void test_ignore_above_with_value_only() {
@@ -34,6 +35,7 @@ public void test_ignore_above_with_value_only() {
3435
// when/then
3536
assertEquals(123, ignoreAbove.get());
3637
assertTrue(ignoreAbove.isSet());
38+
assertTrue(ignoreAbove.valuesPotentiallyIgnored());
3739
}
3840

3941
public void test_ignore_above_with_null_value_should_throw() {
@@ -52,6 +54,7 @@ public void test_ignore_above_with_null_value() {
5254
// when/then
5355
assertEquals(Mapper.IgnoreAbove.IGNORE_ABOVE_DEFAULT_VALUE, ignoreAbove.get());
5456
assertFalse(ignoreAbove.isSet());
57+
assertFalse(ignoreAbove.valuesPotentiallyIgnored());
5558
}
5659

5760
public void test_ignore_above_with_null_value_and_logsdb_index_mode() {
@@ -61,6 +64,7 @@ public void test_ignore_above_with_null_value_and_logsdb_index_mode() {
6164
// when/then
6265
assertEquals(Mapper.IgnoreAbove.IGNORE_ABOVE_DEFAULT_VALUE_FOR_LOGSDB_INDICES, ignoreAbove.get());
6366
assertFalse(ignoreAbove.isSet());
67+
assertTrue(ignoreAbove.valuesPotentiallyIgnored());
6468
}
6569

6670
public void test_ignore_above_with_null_everything() {
@@ -70,6 +74,7 @@ public void test_ignore_above_with_null_everything() {
7074
// when/then
7175
assertEquals(Mapper.IgnoreAbove.IGNORE_ABOVE_DEFAULT_VALUE, ignoreAbove.get());
7276
assertFalse(ignoreAbove.isSet());
77+
assertFalse(ignoreAbove.valuesPotentiallyIgnored());
7378
}
7479

7580
public void test_ignore_above_default_for_standard_indices() {
@@ -79,6 +84,7 @@ public void test_ignore_above_default_for_standard_indices() {
7984
// when/then
8085
assertEquals(Mapper.IgnoreAbove.IGNORE_ABOVE_DEFAULT_VALUE, ignoreAbove.get());
8186
assertFalse(ignoreAbove.isSet());
87+
assertFalse(ignoreAbove.valuesPotentiallyIgnored());
8288
}
8389

8490
public void test_ignore_above_default_for_logsdb_indices() {
@@ -88,6 +94,7 @@ public void test_ignore_above_default_for_logsdb_indices() {
8894
// when/then
8995
assertEquals(Mapper.IgnoreAbove.IGNORE_ABOVE_DEFAULT_VALUE_FOR_LOGSDB_INDICES, ignoreAbove.get());
9096
assertFalse(ignoreAbove.isSet());
97+
assertTrue(ignoreAbove.valuesPotentiallyIgnored());
9198
}
9299

93100
public void test_string_isIgnored() {

0 commit comments

Comments
 (0)