-
Notifications
You must be signed in to change notification settings - Fork 25.3k
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
QL: Adapt nested fields extraction from "fields" API output to the new un-flattened strucutre #68745
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
import java.io.IOException; | ||
import java.time.ZoneId; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
/** | ||
|
@@ -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}]) | ||
field = hit.field(hitName); | ||
} else { | ||
field = hit.field(fieldName); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
if (field != null) { | ||
value = unwrapFieldsMultiValue(field.getValues()); | ||
} | ||
|
@@ -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()) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.