Skip to content

Commit 58c4d2b

Browse files
Both id and query is working checkpoint
1 parent edfa605 commit 58c4d2b

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

server/src/main/java/org/opensearch/index/query/TermsQueryBuilder.java

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,7 @@
6565

6666
import java.io.IOException;
6767
import java.nio.CharBuffer;
68-
import java.util.AbstractList;
69-
import java.util.ArrayList;
70-
import java.util.Arrays;
71-
import java.util.Base64;
72-
import java.util.Collections;
73-
import java.util.HashSet;
74-
import java.util.List;
75-
import java.util.Objects;
76-
import java.util.Set;
68+
import java.util.*;
7769
import java.util.function.Supplier;
7870
import java.util.stream.Collectors;
7971
import java.util.stream.IntStream;
@@ -552,7 +544,7 @@ protected Query doToQuery(QueryShardContext context) throws IOException {
552544

553545
SearchResponse response = context.getClient().search(
554546
new SearchRequest(termsLookup.index())
555-
.source(new SearchSourceBuilder().query(rewrittenQuery).fetchSource(false))
547+
.source(new SearchSourceBuilder().query(rewrittenQuery).fetchSource(true))
556548
).actionGet();
557549

558550
System.out.println("Subquery Response: " + response);
@@ -653,23 +645,35 @@ protected QueryBuilder doRewrite(QueryRewriteContext queryRewriteContext) throws
653645
try {
654646
response = shardContext.getClient().search(
655647
new SearchRequest(termsLookup.index())
656-
.source(new SearchSourceBuilder().query(rewrittenQuery).fetchSource(false))
648+
.source(new SearchSourceBuilder().query(rewrittenQuery).fetchSource(true))
657649
).actionGet();
658-
659-
System.out.println("Extracted Terms: ");
660-
for (SearchHit hit : response.getHits().getHits()) {
661-
System.out.println(XContentMapValues.extractRawValues(termsLookup.path(), hit.getSourceAsMap()));
662-
}
663650
} catch (Exception e) {
664651
throw new IllegalStateException("Failed to execute subquery: " + e.getMessage(), e);
665652
}
666-
667-
// Extract terms from the response
653+
// Extract terms from search hits
668654
List<Object> terms = new ArrayList<>();
669655
for (SearchHit hit : response.getHits().getHits()) {
670-
terms.addAll(XContentMapValues.extractRawValues(termsLookup.path(), hit.getSourceAsMap()));
656+
Map<String, Object> source = hit.getSourceAsMap();
657+
if (source != null) {
658+
try {
659+
List<Object> extracted = XContentMapValues.extractRawValues(termsLookup.path(), source);
660+
terms.addAll(extracted);
661+
System.out.println("Extracted Terms: " + extracted);
662+
} catch (Exception ex) {
663+
System.err.println("Error extracting path '" + termsLookup.path() + "' from source: " + source);
664+
ex.printStackTrace();
665+
}
666+
} else {
667+
System.err.println("Source is null for hit: " + hit);
668+
}
671669
}
672670

671+
// // Extract terms from the response
672+
// List<Object> terms = new ArrayList<>();
673+
// for (SearchHit hit : response.getHits().getHits()) {
674+
// terms.addAll(XContentMapValues.extractRawValues(termsLookup.path(), hit.getSourceAsMap()));
675+
// }
676+
673677
// Return a new TermsQueryBuilder with the fetched terms
674678
return new TermsQueryBuilder(fieldName, terms);
675679
}

0 commit comments

Comments
 (0)