Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/changelog/137394.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 137394
summary: Fix dropped ignore above fields
area: Mapping
type: bug
issues:
- 137360
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ private IOFunction<LeafReaderContext, CheckedIntFunction<List<Object>, IOExcepti
String parentField = searchExecutionContext.parentPath(name());
var parent = searchExecutionContext.lookup().fieldType(parentField);

if (parent instanceof KeywordFieldMapper.KeywordFieldType keywordParent && keywordParent.ignoreAbove().isSet()) {
if (parent instanceof KeywordFieldMapper.KeywordFieldType keywordParent
&& keywordParent.ignoreAbove().valuesPotentiallyIgnored()) {
if (parent.isStored()) {
return storedFieldFetcher(parentField, keywordParent.originalName());
} else if (parent.hasDocValues()) {
Expand All @@ -274,7 +275,7 @@ private IOFunction<LeafReaderContext, CheckedIntFunction<List<Object>, IOExcepti
var kwd = textFieldType.syntheticSourceDelegate();

if (kwd != null) {
if (kwd.ignoreAbove().isSet()) {
if (kwd.ignoreAbove().valuesPotentiallyIgnored()) {
if (kwd.isStored()) {
return storedFieldFetcher(kwd.name(), kwd.originalName());
} else if (kwd.hasDocValues()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1326,7 +1326,7 @@ protected BytesRef preserve(BytesRef value) {
}
}

if (fieldType().ignoreAbove.isSet()) {
if (fieldType().ignoreAbove.valuesPotentiallyIgnored()) {
layers.add(new CompositeSyntheticFieldLoader.StoredFieldLayer(originalName) {
@Override
protected void writeValue(Object value, XContentBuilder b) throws IOException {
Expand Down
11 changes: 10 additions & 1 deletion server/src/main/java/org/elasticsearch/index/mapper/Mapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ default boolean supportsVersion(IndexVersion indexCreatedVersion) {
* This class models the ignore_above parameter in indices.
*/
public static final class IgnoreAbove {

// We use Integer.MAX_VALUE to represent a no-op, accepting all values.
public static final int IGNORE_ABOVE_DEFAULT_VALUE = Integer.MAX_VALUE;
public static final int IGNORE_ABOVE_DEFAULT_VALUE_FOR_LOGSDB_INDICES = 8191;

Expand Down Expand Up @@ -172,6 +172,15 @@ public boolean isSet() {
return Integer.valueOf(get()).equals(defaultValue) == false;
}

/**
* Returns whether values are potentially ignored, either by an explicitly configured ignore_above or by the default value.
*/
public boolean valuesPotentiallyIgnored() {
// We use Integer.MAX_VALUE to represent accepting all values. If the value is anything else, then either we have an
// explicitly configured ignore_above, or we have a non no-op default.
return get() != Integer.MAX_VALUE;
}

/**
* Returns whether the given string will be ignored.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1017,15 +1017,15 @@ public boolean isAggregatable() {
* A delegate by definition must have doc_values or be stored so most of the time it can be used for loading.
*/
public boolean canUseSyntheticSourceDelegateForLoading() {
return syntheticSourceDelegate != null && syntheticSourceDelegate.ignoreAbove().isSet() == false;
return syntheticSourceDelegate != null && syntheticSourceDelegate.ignoreAbove().valuesPotentiallyIgnored() == false;
}

/**
* Returns true if the delegate sub-field can be used for querying only (ie. isIndexed must be true)
*/
public boolean canUseSyntheticSourceDelegateForQuerying() {
return syntheticSourceDelegate != null
&& syntheticSourceDelegate.ignoreAbove().isSet() == false
&& syntheticSourceDelegate.ignoreAbove().valuesPotentiallyIgnored() == false
&& syntheticSourceDelegate.isIndexed();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ protected SyntheticSourceSupport syntheticSourceSupport() {
() -> new FlattenedSortedSetDocValuesSyntheticFieldLoader(
fullPath(),
fullPath() + KEYED_FIELD_SUFFIX,
fieldType().ignoreAbove.isSet() ? fullPath() + KEYED_IGNORED_VALUES_FIELD_SUFFIX : null,
fieldType().ignoreAbove.valuesPotentiallyIgnored() ? fullPath() + KEYED_IGNORED_VALUES_FIELD_SUFFIX : null,
leafName()
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public void test_ignore_above_with_value_and_index_mode_and_index_version() {
// when/then
assertEquals(123, ignoreAbove.get());
assertTrue(ignoreAbove.isSet());
assertTrue(ignoreAbove.valuesPotentiallyIgnored());
}

public void test_ignore_above_with_value_only() {
Expand All @@ -34,6 +35,7 @@ public void test_ignore_above_with_value_only() {
// when/then
assertEquals(123, ignoreAbove.get());
assertTrue(ignoreAbove.isSet());
assertTrue(ignoreAbove.valuesPotentiallyIgnored());
}

public void test_ignore_above_with_null_value_should_throw() {
Expand All @@ -52,6 +54,7 @@ public void test_ignore_above_with_null_value() {
// when/then
assertEquals(Mapper.IgnoreAbove.IGNORE_ABOVE_DEFAULT_VALUE, ignoreAbove.get());
assertFalse(ignoreAbove.isSet());
assertFalse(ignoreAbove.valuesPotentiallyIgnored());
}

public void test_ignore_above_with_null_value_and_logsdb_index_mode() {
Expand All @@ -61,6 +64,7 @@ public void test_ignore_above_with_null_value_and_logsdb_index_mode() {
// when/then
assertEquals(Mapper.IgnoreAbove.IGNORE_ABOVE_DEFAULT_VALUE_FOR_LOGSDB_INDICES, ignoreAbove.get());
assertFalse(ignoreAbove.isSet());
assertTrue(ignoreAbove.valuesPotentiallyIgnored());
}

public void test_ignore_above_with_null_everything() {
Expand All @@ -70,6 +74,7 @@ public void test_ignore_above_with_null_everything() {
// when/then
assertEquals(Mapper.IgnoreAbove.IGNORE_ABOVE_DEFAULT_VALUE, ignoreAbove.get());
assertFalse(ignoreAbove.isSet());
assertFalse(ignoreAbove.valuesPotentiallyIgnored());
}

public void test_ignore_above_default_for_standard_indices() {
Expand All @@ -79,6 +84,7 @@ public void test_ignore_above_default_for_standard_indices() {
// when/then
assertEquals(Mapper.IgnoreAbove.IGNORE_ABOVE_DEFAULT_VALUE, ignoreAbove.get());
assertFalse(ignoreAbove.isSet());
assertFalse(ignoreAbove.valuesPotentiallyIgnored());
}

public void test_ignore_above_default_for_logsdb_indices() {
Expand All @@ -88,6 +94,7 @@ public void test_ignore_above_default_for_logsdb_indices() {
// when/then
assertEquals(Mapper.IgnoreAbove.IGNORE_ABOVE_DEFAULT_VALUE_FOR_LOGSDB_INDICES, ignoreAbove.get());
assertFalse(ignoreAbove.isSet());
assertTrue(ignoreAbove.valuesPotentiallyIgnored());
}

public void test_string_isIgnored() {
Expand Down
Loading