用关系数据进行弹性搜索的河流

时间:2014-12-16 17:29:47

标签: sql elasticsearch elasticsearch-jdbc-river

考虑以下sql架构:

enter image description here

Table_2和Table_1具有多对多的关系

现在我正在尝试创建一个弹性搜索河,它将从table_2中提取所有数据,但我也希望来自table_1的行,而不仅仅是id。

以下是我认为将成为我的SQL:

select t2.*, t1.Name from [Table_2] t2
join [Table_3] t3 on t2.ID = t3.table_2
join [Table_1] t1 on t1.ID = t3.table_1

现在执行此操作后,我注意到我在Table_3中为每个关系获取了重复的行IE我会得到一行,我理解为什么这是我想要的是Table_2的一个条目,其中包含一个表项。< / p>

这就是我现在的弹性

{
    "took": 1,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "failed": 0
    },
    "hits": {
        "total": 2,
        "max_score": 1,
        "hits": [
            {
                "_index": "test_relation",
                "_type": "relation",
                "_id": "AUpUGlvaRCP4Gzd2p3K4",
                "_score": 1,
                "_source": {
                    "Name": [
                        "table_2test",
                        "Test1"
                    ],
                    "ID": 1
                }
            },
            {
                "_index": "test_relation",
                "_type": "relation",
                "_id": "AUpUGlvaRCP4Gzd2p3K5",
                "_score": 1,
                "_source": {
                    "Name": [
                        "table_2test",
                        "Test2"
                    ],
                    "ID": 1
                }
            }
        ]
    }
}

但我希望它看起来像:

{
    "took": 1,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "failed": 0
    },
    "hits": {
        "total": 1,
        "max_score": 1,
        "hits": [
            {
                "_index": "test_relation",
                "_type": "relation",
                "_id": "AUpUGlvaRCP4Gzd2p3K4",
                "_score": 1,
                "_source": {
                    "Name": [
                        "table_2test",
                    ],
                    Table_1 :[
                        {"Name": "Test1", "ID": "1"},
                        {"Name": "Test2", "ID": "2"}
                    ]
                    "ID": 1
                }
            }
        ]
    }
}

我希望能够为sql使用elasticsearch river,但我不确定它是否允许这种查询。

0 个答案:

没有答案