Skip to content

Commit

Permalink
Simplifying the default_field_logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
afoucret committed Nov 7, 2024
1 parent 922378b commit 4ecf192
Showing 1 changed file with 2 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
import org.elasticsearch.index.query.QueryRewriteContext;

import java.time.ZoneId;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

Expand Down Expand Up @@ -59,22 +57,12 @@ public String defaultField() {
}

public Set<String> resolveFieldNames(String fieldNamePattern) {
if (fieldNamePattern == null) {
return resolveDefaultFieldNames();
}

assert fieldNamePattern != null && fieldNamePattern.isEmpty() == false : "fieldNamePattern cannot be null or empty";
return queryRewriteContext.getMatchingFieldNames(fieldNamePattern);
}

public Set<String> resolveDefaultFieldNames() {
Set<String> resolvedFieldNames = new HashSet<>();
List<String> defaultFields = defaultField != null
? List.of(defaultField)
: queryRewriteContext.getIndexSettings().getDefaultFields();

defaultFields.forEach(fieldNamePattern -> resolvedFieldNames.addAll(resolveFieldNames(fieldNamePattern)));

return Collections.unmodifiableSet(resolvedFieldNames);
return resolveFieldNames(defaultField);
}

public MappedFieldType fieldType(String fieldName) {
Expand Down

0 comments on commit 4ecf192

Please sign in to comment.