Hybrid search by using knn and query in java client

I want the hybrid search by using both the knn option and a query on the page below with java client.

With spring-boot 3.1.5 and elasticsarch-java 8.7.1 environment,
I made some codes as below, but seems like .withKnnQuery(knnQuery) condition is not processed. Is there any way?

MatchQuery matchQuery = new MatchQuery.Builder().field(textfield).query(searchText).boost(1.0f).build();
BoolQuery boolQuery = new BoolQuery.Builder().must(List.of(matchQuery._toQuery())).build();

TermsQuery termsQuery = new TermsQuery.Builder().field("ownerNm").terms(new TermsQueryField.Builder().value(List.of(FieldValue.of("luis"))).build()).build();
KnnQuery knnQuery = new KnnQuery.Builder()
Query searchQuery = NativeQuery.builder()

SearchHits<TetstIndex> searchHits = operations.search(searchQuery, TestIndex.class);

Hi @wshan13 .

You can try replace this:

for this:

   SearchRequest sr = SearchRequest.of(s -> s

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.