F21*_*F21 7 many-to-many elasticsearch
我知道在弹性搜索中,我们可以在文档之间建立子/父关系.
然后,在索引时,我可以传递父ID,以便链接子文档和父文档:
$ curl -XPUT localhost:9200/blogs/blog_tag/1122?parent=1111 -d '{ "tag" : "something"}'
Run Code Online (Sandbox Code Playgroud)
无论如何,在弹性搜索中建立多对多的关系?
数据驻留在具有以下模式的MySQL数据库中:
account
========
id
name
some_property
group
========
id
name
description
account_group
=============
account_id
group_id
primary_group //This is 1 or 0 depending on whether the group is the primary group for that account.
Run Code Online (Sandbox Code Playgroud)
这是我目前的映射account(请原谅数组符号,我在PHP中使用Elastica与我的elasticsearch服务器通信):
**Mapping for account**
'name' => array(
'type' => 'string'),
'some_property' => array(
'type' => 'string'),
'groups' => array(
'properties' => array(
'id' => array('type' => 'integer'),
'primary' => array('type' => 'boolean')
)
),
**Mapping for group**
'name' => array(
'type' => 'string'),
'description'=> array(
'type' => 'string')
Run Code Online (Sandbox Code Playgroud)
这种方法的问题是,如果从索引中删除一个组,我将需要遍历每个帐户并从每个帐户中删除组ID.这对我来说似乎有点低效.我还假设在使用elasticsearch的子/父关系时这不是问题.
无论如何都要在弹性搜索中建立多对多的关系?
F21*_*F21 11
没有办法模拟多对多关系.
唯一的方法是在每个帐户中存储每个组的ID,就像我上面所做的那样.
Elasticsearch非常有效,因此重建索引通常是一种可接受的解决方案.此外,elasticsearch具有文档的概念,而不是关系存储系统,因此可能永远不会实现多对多关系.