GET feeds/_search
{
"query": {
"bool": {
"should": [
{
"nested": {
"path": "comment",
"query": {
"match": {
"comment.c_text": "This is mateen"
}
},"inner_hits": {}
}
},
{
"term": {
"title.keyword": {
"value": "This is mateen"
}
}
},
{
"term": {
"body.keyword": {
"value": "This is mateen"
}
}
}
]
}
}
}
Map如下所示:
PUT feeds
{
"mappings": {
"properties": {
"comment":{
"type": "nested"
}
}
}
}
我使用的是Elasticsearch 7.17.3.为了在我的springboot中搜索Elasticsearch的所有文档,我编写了下面的代码,它给了我确切的输出:
public List<feed> searchAllDocuments() throws IOException {
SearchRequest searchRequest = SearchRequest.of(s -> s.index(indexName));
SearchResponse searchResponse = elasticsearchClient.search(searchRequest, feed.class);
List<Hit> hits = searchResponse.hits().hits();
List<feed> feeds = new ArrayList<>();
feed f=null;
for (Hit object : hits) {
f = (feed) object.source();
feeds.add(f);
}
return feeds;
}
有谁能帮我把查询转换成springboot应用程序吗?我是新手,需要你的指导
1条答案
按热度按时间myzjeezk1#
如果您使用新的Java API客户端,请尝试以下代码: