Skip to content

Commit

Permalink
support new parameter to fetch stored field in terms lookup
Browse files Browse the repository at this point in the history
Signed-off-by: bowenlan-amzn <[email protected]>
  • Loading branch information
bowenlan-amzn committed Jul 20, 2024
1 parent 7b360b6 commit 03ff662
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,9 @@ protected Query doToQuery(QueryShardContext context) throws IOException {
private void fetch(TermsLookup termsLookup, Client client, ActionListener<List<Object>> actionListener) {
GetRequest getRequest = new GetRequest(termsLookup.index(), termsLookup.id());
getRequest.preference("_local").routing(termsLookup.routing());
getRequest.storedFields(termsLookup.path());
if (termsLookup.store()) {
getRequest.storedFields(termsLookup.path());
}
client.get(getRequest, ActionListener.delegateFailure(actionListener, (delegatedListener, getResponse) -> {
List<Object> terms = new ArrayList<>();
terms.addAll(getResponse.getField(termsLookup.path()).getValues());
Expand Down
8 changes: 8 additions & 0 deletions server/src/main/java/org/opensearch/indices/TermsLookup.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ public TermsLookup routing(String routing) {
return this;
}

private boolean store;
public boolean store() { return store; }
public TermsLookup store(boolean store) {
this.store = store;
return this;
}

private static final ConstructingObjectParser<TermsLookup, Void> PARSER = new ConstructingObjectParser<>("terms_lookup", args -> {
String index = (String) args[0];
String id = (String) args[1];
Expand All @@ -132,6 +139,7 @@ public TermsLookup routing(String routing) {
PARSER.declareString(constructorArg(), new ParseField("id"));
PARSER.declareString(constructorArg(), new ParseField("path"));
PARSER.declareString(TermsLookup::routing, new ParseField("routing"));
PARSER.declareBoolean(TermsLookup::store, new ParseField("store"));
}

public static TermsLookup parseTermsLookup(XContentParser parser) throws IOException {
Expand Down

0 comments on commit 03ff662

Please sign in to comment.