spring data elasticsearch 跨多个索引搜索时,如何在搜索结果中获取索引名称?
当搜索多个索引时,elasticsearch的“多重匹配”查询返回搜索结果中的索引名称spring data elasticsearch 跨多个索引搜索时,如何在搜索结果中获取索引名称?,spring-data-elasticsearch,spring Data Elasticsearch,当搜索多个索引时,elasticsearch的“多重匹配”查询返回搜索结果中的索引名称 GET localhost:9200/users,locations/_search { "query":{ "multi_match":{ "query": "pus", "type": "bool_prefix",
GET localhost:9200/users,locations/_search
{
"query":{
"multi_match":{
"query": "pus",
"type": "bool_prefix",
"fields":[
"name",
"name._2gram",
"name._3gram"
]
}
}
}
响应包含\u index
字段,该字段告诉您从中获得结果的索引
"hits": [{
"_index": "locations",
"_type": "_doc",
"_id": "418",
"_score": 1.0,
"_source": {
"name": "pusan-kwangyokshi | korea republic of | asia",
"@timestamp": "2020-09-21T07:12:34.432Z"
}
},
{
"_index": "users",
"_type": "_doc",
"_id": "4",
"_score": 1.0,
"_source": {
"name": "Puspjer taojomi",
"uniqueId": "skjhs-sklhjs125",
"accountStatus": 1,
"email": "xyz@gmail.com",
"@timestamp": "2020-09-22T09:57:22.977Z"
}
},
{
"_index": "users",
"_type": "_doc",
"_id": "52",
"_score": 1.0,
"_source": {
"name": "Puspa yabna",
"uniqueId": "sjhslkj-ta18ynsarda5",
"accountStatus": 1,
"email": "abc@gmail.com",
"@timestamp": "2020-09-22T09:57:23.121Z"
}
}
]
spring data elasticsearch中使用的hits
类是SearchHits
,SearchHit
具有字段id
,content
,score
,用于从elasticsearch查询中获取类似的数据。但它不包含用于存储\u索引
字段信息的相关字段
支持了吗?我需要发送搜索命中类型(\u index
name),根据该类型,客户端应用程序将生成一些URL
这是我使用spring的搜索查询
final NativeSearchQuery query = new NativeSearchQuery(QueryBuilders.multiMatchQuery(q, "name", "name._2gram", "name._3gram").type(MultiMatchQueryBuilder.Type.BOOL_PREFIX));
IndexCoordinates indexCoordinates = IndexCoordinates.of("users","locations");
return operations.search(query, OutDto.class, indexCoordinates)
.getSearchHits()
.stream()
.map(SearchHit::getContent)
.collect(Collectors.toList());
//The DTO class
public class OutDto{
private Integer id;
private String uniqueId;
private String name;
private String index;
}
这是在里程碑版本4.1.M1之后的4.1版本中实现的
关于如何使用RC或里程碑版本的信息可以在上找到。找不到工件org.springframework.data:spring data elasticsearch:pom:4.1.0.M1在Central中这就是为什么我给出了链接,其中记录了如何获得里程碑或RC版本-您应该使用4.1.0.-RC1