如何使用 elasticsearch-dsl-py 连接两个 ElasticSearch 索引?

How do I join two ElasticSearch indices using elasticsearch-dsl-py?

两个指数文件如下:

class First(Document):

    class Index:
       name  = 'first'
       
   case_id = Keyword()
   name = Text()
   
class Second(Document):

    class Index:
       name  = 'second'
       
   case_id = Keyword()
   status = Text()

我只想以 SQL 格式执行如下查询

select * from first as f, second as s where s.case_id = f.case_id or s.status = 'xyz'

如何使用弹性搜索 dsl 查询来实现?

  1. Elastic Search 不支持索引之间的连接

    原因:Elastic Search 不是关系型的,非规范化数据应该存储在这里。

    摘自以下 elastic Doc

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.

  1. 根据用例使用嵌套或 parent/child 映射来存储数据。

    嵌套: 如果嵌套文档的基数非常低并且索引读取密集

    Parent/child: 如果子基数比父基数高,parent/child需要经常更新