是否可以跨多个索引查询关系?我知道我可以跨多个索引进行搜索,但我会得到两个不相交的结果集。
例如,我有两个索引“客户”和“地址”,它们通过客户索引中的地址键相关联。我想在一次查询中获取住在“纽约”的所有名为“John”的客户。 ES 能否“加入”address 和 customer 的两个结果集并给我所有来自 NY 的 Johns?
我感觉 ES 不是为 rdbms 风格的索引连接而设计的。不幸的是,将索引展平为一个索引不是一种选择。多次查询也不是一种选择。
最佳答案
ES 是基于文档的 No-SQL,因此您实际上无法在本地进行连接,它不是关系型:这就是重点。
Performing full SQL-style joins in a distributed system like Elasticsearch is prohibitively expensive. Instead, Elasticsearch offers two forms of join which are designed to scale horizontally.
https://www.elastic.co/guide/en/elasticsearch/reference/current/joining-queries.html
一个有效的解决方案是复制数据,也称为 denormalizing数据,这避免了连接,但在存储和代码逻辑方面会更重。
The way to get the best search performance out of Elasticsearch is to use it as it is intended, by denormalizing your data at index time. Having redundant copies of data in each document that requires access to it removes the need for joins.
阅读:https://www.elastic.co/guide/en/elasticsearch/guide/current/denormalization.html
如果您想要最佳搜索速度,请从现有索引重建非规范化索引。
关于Elasticsearch:使用关系查询多个索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49550556/