繁体   English   中英

如何使用 Spring elasticsearch 合并来自两个不同索引的文档

[英]How to merge documents from two different indexes using Spring elasticsearch

我是弹性搜索的新手,我正在尝试在应用程序中使用 spring 数据弹性搜索。 我有一个要求,其中有两个单独的索引,我想根据某种条件在一个查询中从两个索引中获取文档。

我会尝试用相同场景的示例来解释它。 单个索引有两个不同的类。

@Document(indexName = "Book", type = "Book")
public class Book {

@Id
private String id;

@Field(type = FieldType.String)
private String bookName;

@Field(type = FieldType.Integer)
private int price;

@Field(type = FieldType.String)
private String authorName;

//Getters and Setters

}

还有一个 class 作者

@Document(indexName = "Author", type = "Author")
public Class Author{

@Id
private String id;

@Field(type = FieldType.String)
private String authorName;

//Getters and setters
}

所以有两个索引,一本书和其他作者。 我想获取 Book 索引中的 authorName 等于 Author 索引中的 authorName 的所有文档。 我可以从两个索引中获取详细信息作为合并结果之类的单个文档吗? 如果有人可以为此用例提出解决方案,那将非常有帮助。

非常感谢您的回答

你的问题不清楚。 Author 索引中的文档与 Book 索引中的文档不同。 它们是两个不同的文件。 我能想到的最接近的事情是使用相同的查询查询多个索引 - 只需将多个索引添加到 indexCoordinates.of 方法以在两个索引中搜索相同的 filed\value。 例如:

elasticsearchTemplae.search(query, returnedObjectClass, indexCoordinates.of("Author", "Book")). 

它将返回所有包含两个索引的搜索结果,这些索引必须满足查询条件,无论它们是什么。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM