Spring Boot &弹性搜索 |多索引搜索功能 [英] Spring Boot & Elastic Search | Multi-index search functionality
问题描述
我有一个 spring boot API,它有三个模型(用户、项目、技能),目前我可以毫无问题地搜索任何索引,如下所示:
I have a spring boot API which has three models (User, Projects, Skills) currently I can search any of the indexes without issue as below:
log.info("Search with query {}", query);
Pageable pageable = PageRequest.of(page, size);
QueryBuilder queryBuilder =
QueryBuilders
.multiMatchQuery(query, "projectDescription", "projectName", "projectTechStack")
.fuzziness(Fuzziness.ONE);
Query searchQuery = new NativeSearchQueryBuilder()
.withFilter(queryBuilder)
.withPageable(pageable)
.build();
SearchHits<UserProjects> projectHits =
elasticsearchOperations
.search(searchQuery, UserProjects.class,
IndexCoordinates.of(elasticProjectsIndex));
但是我想搜索所有三个索引并将它们映射到正确的 POJO.我比较坚持这一点.此外,这就是我非常困惑的地方,我想要一个分页的响应,其中包含以下内容:
However I would like to search all three indices and map them to the correct POJO. I'm rather stuck on this. Furthermore and this is where I get VERY stuck is, I would like to have a response paginated which would contain lets say the following:
User results: 3 of 100
Project Results 4 of 10
etc etc
基本上,在我的前端,我可以知道是否应该显示单击此处查看更多用户结果";将仅在用户索引上运行搜索的链接.
Basically so on my front end I can know if I should show a "click here for more User results" link which would run a search just on the user index.
如果有人可以帮助我,那就太棒了.
If anyone can please help me that would be amazing.
谢谢
推荐答案
如果用户想要跨多个维度/索引进行搜索,那么 MultiSearch 将非常有用.
If a user wants to search across multiple dimensions/indexes then MultiSearch will be very useful.
示例用法: 用户可以亲自搜索java",文章&职位索引(在 LinkedIn 类型的应用程序中),并且能够根据请求配置分页.
Example Usage: User can search for 'java' in person, article & job indices (in a LinkedIn type application) and would be able to configure pagination per request.
这篇关于Spring Boot &弹性搜索 |多索引搜索功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!