Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…fix_non_snapshot_error_messages
  • Loading branch information
astefan committed Sep 13, 2024
2 parents defc193 + 86a88d7 commit eb6de84
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 12 deletions.
5 changes: 5 additions & 0 deletions docs/changelog/112850.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 112850
summary: Fix synthetic source field names for multi-fields
area: Mapping
type: bug
issues: []
2 changes: 1 addition & 1 deletion docs/reference/query-dsl/knn-query.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ to <<nested-knn-search, top level nested kNN search>>:
* kNN search over nested dense_vectors diversifies the top results over
the top-level document
* `filter` over the top-level document metadata is supported and acts as a
post-filter
pre-filter
* `filter` over `nested` field metadata is not supported

A sample query can look like below:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ public MatchOnlyTextFieldType fieldType() {

@Override
protected SyntheticSourceSupport syntheticSourceSupport() {
var loader = new StringStoredFieldFieldLoader(fieldType().storedFieldNameForSyntheticSource(), leafName()) {
var loader = new StringStoredFieldFieldLoader(fieldType().storedFieldNameForSyntheticSource(), fieldType().name(), leafName()) {
@Override
protected void write(XContentBuilder b, Object value) throws IOException {
b.value((String) value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ protected void write(XContentBuilder b, Object value) throws IOException {

var kwd = TextFieldMapper.SyntheticSourceHelper.getKeywordFieldMapperForSyntheticSource(this);
if (kwd != null) {
return new SyntheticSourceSupport.Native(kwd.syntheticFieldLoader(leafName()));
return new SyntheticSourceSupport.Native(kwd.syntheticFieldLoader(fullPath(), leafName()));
}

return super.syntheticSourceSupport();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,9 @@ public String[] resolveNodes(String... nodes) {
* Returns the changes comparing this nodes to the provided nodes.
*/
public Delta delta(DiscoveryNodes other) {
if (this == other) {
return new Delta(this.masterNode, this.masterNode, localNodeId, List.of(), List.of());
}
final List<DiscoveryNode> removed = new ArrayList<>();
final List<DiscoveryNode> added = new ArrayList<>();
for (DiscoveryNode node : other) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1037,13 +1037,13 @@ protected SyntheticSourceSupport syntheticSourceSupport() {
}

if (fieldType.stored() || hasDocValues) {
return new SyntheticSourceSupport.Native(syntheticFieldLoader(leafName()));
return new SyntheticSourceSupport.Native(syntheticFieldLoader(fullPath(), leafName()));
}

return super.syntheticSourceSupport();
}

public SourceLoader.SyntheticFieldLoader syntheticFieldLoader(String simpleName) {
public SourceLoader.SyntheticFieldLoader syntheticFieldLoader(String fullFieldName, String leafFieldName) {
assert fieldType.stored() || hasDocValues;

var layers = new ArrayList<CompositeSyntheticFieldLoader.Layer>();
Expand Down Expand Up @@ -1081,6 +1081,6 @@ protected void writeValue(Object value, XContentBuilder b) throws IOException {
});
}

return new CompositeSyntheticFieldLoader(simpleName, fullPath(), layers);
return new CompositeSyntheticFieldLoader(leafFieldName, fullFieldName, layers);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,25 @@
import static java.util.Collections.emptyList;

public abstract class StringStoredFieldFieldLoader implements SourceLoader.SyntheticFieldLoader {
private final String name;
private final String storedFieldLoaderName;
private final String fullName;
private final String simpleName;

private List<Object> values = emptyList();

public StringStoredFieldFieldLoader(String name, String simpleName) {
this.name = name;
public StringStoredFieldFieldLoader(String fullName, String simpleName) {
this(fullName, fullName, simpleName);
}

public StringStoredFieldFieldLoader(String storedFieldLoaderName, String fullName, String simpleName) {
this.storedFieldLoaderName = storedFieldLoaderName;
this.fullName = fullName;
this.simpleName = simpleName;
}

@Override
public final Stream<Map.Entry<String, StoredFieldLoader>> storedFieldLoaders() {
return Stream.of(Map.entry(name, newValues -> values = newValues));
return Stream.of(Map.entry(storedFieldLoaderName, newValues -> values = newValues));
}

@Override
Expand Down Expand Up @@ -72,6 +78,6 @@ public final DocValuesLoader docValuesLoader(LeafReader reader, int[] docIdsInLe

@Override
public String fieldName() {
return name;
return fullName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1462,7 +1462,7 @@ protected void write(XContentBuilder b, Object value) throws IOException {

var kwd = SyntheticSourceHelper.getKeywordFieldMapperForSyntheticSource(this);
if (kwd != null) {
return new SyntheticSourceSupport.Native(kwd.syntheticFieldLoader(leafName()));
return new SyntheticSourceSupport.Native(kwd.syntheticFieldLoader(fullPath(), leafName()));
}

return super.syntheticSourceSupport();
Expand Down

0 comments on commit eb6de84

Please sign in to comment.