我正在使用 Elasticcsearch 7.3。我只想从我的索引中使用 JAVA Api 获取所有文档的两条记录。我正在使用以下代码,但它返回空对象。
RestHighLevelClient client;
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
sourceBuilder.fetchSource("recipe_ID,recipe_url", null);
sourceBuilder.from(0);
SearchRequest searchRequest = new SearchRequest("recipes");
searchRequest.source(sourceBuilder);
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
SearchHit searchHit = searchResponse.getHits().getAt(0);
String resultString = searchHit.getSourceAsString();
return resultString;
我只需要在结果中包含两个字段recipe_ID和recipe_url。