Elasticsearch:使用关系查询多个索引

标签 elasticsearch

是否可以跨多个索引查询关系?我知道我可以跨多个索引进行搜索,但我会得到两个不相交的结果集。

例如,我有两个索引“客户”和“地址”,它们通过客户索引中的地址键相关联。我想在一次查询中获取住在“纽约”的所有名为“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/

相关文章:

c# - Elasticsearch 日期直方图存储桶计数过滤

elasticsearch - ElasticSearch:是否可以定义备用键

elasticsearch - 将父文档_score和function_score中的_score乘以嵌套查询

java - ElasticSearch 中 BoolQuery 的 "filter"的用途是什么?

symfony - 在没有 ES 服务器的情况下使用 FOSElasticaBundle 对 Symfony 应用程序进行单元测试?

elasticsearch - Elasticsearch:嵌套字段上的 “must”查询

elasticsearch - 使用NaN值对百分位数聚合排序

elasticsearch - 为什么我在 Elasticsearch 中的日期查询失败?

json - 对多个字段进行ElasticSearch过滤(聚合)

json - 将节点Filebeat接收到Elasticsearch