Skip to content

QL: Adapt nested fields extraction from "fields" API output to the new un-flattened strucutre #68745

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
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 @@ -17,6 +17,7 @@
import java.io.IOException;
import java.time.ZoneId;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
Expand Down Expand Up @@ -78,7 +79,13 @@ public void writeTo(StreamOutput out) throws IOException {
@Override
public Object extract(SearchHit hit) {
Object value = null;
DocumentField field = hit.field(fieldName);
DocumentField field = null;
if (hitName != null) {
// a nested field value is grouped under the nested parent name (ie dep.dep_name lives under "dep":[{dep_name:value}])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// a nested field value is grouped under the nested parent name (ie dep.dep_name lives under "dep":[{dep_name:value}])
// a nested field value is grouped under the nested parent name (ie dep.dep_name lives under "dep":[{"dep_name":value}])

field = hit.field(hitName);
} else {
field = hit.field(fieldName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make sure, the fieldName is in this case a "doc-top-level" field, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fieldName is the full field name (including the path): dep.dep_name for example.

}
if (field != null) {
value = unwrapFieldsMultiValue(field.getValues());
}
Expand All @@ -89,6 +96,10 @@ protected Object unwrapFieldsMultiValue(Object values) {
if (values == null) {
return null;
}
if (values instanceof Map && hitName != null) {
// extract the sub-field from a nested field (dep.dep_name -> dep_name)
return unwrapFieldsMultiValue(((Map<?,?>) values).get(fieldName.substring(hitName.length() + 1)));
}
if (values instanceof List) {
List<?> list = (List<?>) values;
if (list.isEmpty()) {
Expand Down