【问题标题】:Inner Join operations between two Elastic Types inside a single Index单个索引内的两个弹性类型之间的内连接操作
【发布时间】:2016-09-10 07:50:08
【问题描述】:

我在弹性索引中有两种类型,例如员工和城市,

员工类型的文档结构是这样的

[{
    "_index": "zase",
    "_type": "Employees",
    "_id": "100",
    "_score": 1,
    "_source": {
        "sid": 100,
        "name": "San Andreas",
        "stageid": 0
    }
},
{
    "_index": "zase",
    "_type": "Employees",
    "_id": "101",
    "_score": 1,
    "_source": {
        "sid": 101,
        "name": "Zack",
        "stageid": 0
    }
}]

类型城市的文档结构如下,

[{
    "_index": "zase",
    "_type": "Cities",
    "_id": "1",
    "_score": 1,
    "_source": {
        "sid": 1,
        "name": "Virginia",
        "EmployeesID": [
            0:100,
            1:125,
            2:143
        ]
    }
},
{
    "_index": "zase",
    "_type": "Cities",
    "_id": "2",
    "_score": 1,
    "_source": {
        "sid": 2,
        "name": "New Field",
        "EmployeesID": [
            0: 110
        ]
    }
}]  

使用城市名称“弗吉尼亚”查询弹性搜索时,我需要获取 Cities.EmployeesID ==Employees.sid 的员工信息,

在 Elastic Search 中是否可以跨不同类型执行此 RDBMS Join 操作? 任何帮助将不胜感激。

【问题讨论】:

    标签: elasticsearch lucene nest nosql


    【解决方案1】:

    如果这是您的数据检索的主要用例,您也可以考虑使用parent-child 关系。

    【讨论】:

    • 只要知道,如果您有一个员工可以在两个不同的城市(在一个城市兼职,另一个在另一个城市兼职)的用例,那么父子将无法工作
    【解决方案2】:

    ES 中尚不支持 JOIN 查询,尽管有一个正在讨论的 issue 和一个试图提供该功能的 pull request,但工作目前因一些冲突而停滞不前。

    同时,对于您的简单用例,您可能可以使用elasticsearch-sql 插件来实现您想要的。

    【讨论】:

    • 如何在 Elastic 的 dotnet 客户端中使用 elasticsearch-sql ?我正在使用 NEST 查询从弹性中检索数据。
    • 该插件公开了一个endpoint called /_sql,它接受一个包含您要执行的SQL查询的sql参数。您可能会尝试从 NEST 访问该端点。查看示例here
    猜你喜欢
    • 1970-01-01
    • 2012-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-29
    相关资源
    最近更新 更多