考虑以下 sql 模式:
其中 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 的一个条目,其中包含表一的条目。
这就是我现在得到的弹性
{
"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 使用弹性搜索河,但我不确定它是否允许这种查询。