Skip to content

[8.x] backport SearchContextStats changes #129978

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,6 @@ private SearchContextStats(List<SearchExecutionContext> contexts) {
assert contexts != null && contexts.isEmpty() == false;
}

@Override
public boolean exists(FieldName field) {
var stat = cache.computeIfAbsent(field.string(), this::makeFieldStats);
return stat.config.exists;
}

private FieldStats makeFieldStats(String field) {
var stat = new FieldStats();
stat.config = makeFieldConfig(field);
Expand All @@ -103,20 +97,19 @@ private FieldConfig makeFieldConfig(String field) {
// since if it's missing, deleted documents won't change that
for (SearchExecutionContext context : contexts) {
if (context.isFieldMapped(field)) {
exists = exists || true;
MappedFieldType type = context.getFieldType(field);
indexed = indexed && type.isIndexed();
hasDocValues = hasDocValues && type.hasDocValues();
if (type instanceof TextFieldMapper.TextFieldType t) {
hasExactSubfield = hasExactSubfield && t.canUseSyntheticSourceDelegateForQuerying();
} else {
hasExactSubfield = false;
}
var type = context.getFieldType(field);
exists |= true;
indexed &= type.isIndexed();
hasDocValues &= type.hasDocValues();
hasExactSubfield &= type instanceof TextFieldMapper.TextFieldType t && t.canUseSyntheticSourceDelegateForQuerying();
} else {
indexed = false;
hasDocValues = false;
hasExactSubfield = false;
}
if (exists && indexed == false && hasDocValues == false && hasExactSubfield == false) {
break;
}
}
if (exists == false) {
// if it does not exist on any context, no other settings are valid
Expand All @@ -126,22 +119,34 @@ private FieldConfig makeFieldConfig(String field) {
}
}

private boolean fastNoCacheFieldExists(String field) {
for (SearchExecutionContext context : contexts) {
if (context.isFieldMapped(field)) {
return true;
}
}
return false;
}

@Override
public boolean exists(FieldName field) {
var stat = cache.get(field.string());
return stat != null ? stat.config.exists : fastNoCacheFieldExists(field.string());
}

@Override
public boolean isIndexed(FieldName field) {
var stat = cache.computeIfAbsent(field.string(), this::makeFieldStats);
return stat.config.indexed;
return cache.computeIfAbsent(field.string(), this::makeFieldStats).config.indexed;
}

@Override
public boolean hasDocValues(FieldName field) {
var stat = cache.computeIfAbsent(field.string(), this::makeFieldStats);
return stat.config.hasDocValues;
return cache.computeIfAbsent(field.string(), this::makeFieldStats).config.hasDocValues;
}

@Override
public boolean hasExactSubfield(FieldName field) {
var stat = cache.computeIfAbsent(field.string(), this::makeFieldStats);
return stat.config.hasExactSubfield;
return cache.computeIfAbsent(field.string(), this::makeFieldStats).config.hasExactSubfield;
}

@Override
Expand Down Expand Up @@ -231,7 +236,7 @@ public boolean isSingleValue(FieldName field) {
var stat = cache.computeIfAbsent(fieldName, this::makeFieldStats);
if (stat.singleValue == null) {
// there's no such field so no need to worry about multi-value fields
if (exists(field) == false) {
if (stat.config.exists == false) {
stat.singleValue = true;
} else {
// fields are MV per default
Expand Down