弹性搜索中的许多关系 [英] Many to many relationships in elasticsearch
问题描述
我知道在弹性搜索中,我们可以在文档之间小孩/父母关系 。
I know that in elasticsearch, we can have child/parent relationships between documents.
然后,当索引时,我可以传递父ID,以便链接到小孩和父文档:
And then, when indexing, I can pass the parent id so that the child and parent documents are linked:
$ curl -XPUT localhost:9200/blogs/blog_tag/1122?parent=1111 -d '{ "tag" : "something"}'
有没有办法在弹性搜索中建立多对多的关系?
Is there anyway to model a many to many relationship in elasticsearch?
数据驻留在具有以下架构的MySQL数据库中:
Data is resides in a MySQL database with the following schema:
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.
这是目前我的映射帐户
请原谅阵列符号,我使用PHP中的 Elastica 与我的弹性搜索服务器通话):
This is currently my mapping for account
(please excuse the array notation, I am using Elastica in PHP to talk to my elasticsearch server):
**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')
就是说,如果从索引中删除了一个组,我将需要通过每个帐户,并从每个帐户中删除组ID。这似乎对我来说有点低效。我还假定在使用弹性搜索的子/父关系时这不会是一个问题。
The problem with this approach is that if a group is deleted from the index, I will need to go through each account and delete the group id from each account. This seems to be a bit inefficient to me. I also presume that this would not be an issue when using elasticsearch's child/parent relationships.
有没有办法在弹性搜索中建立多对多关系?
Is there anyway to model many-to-many relationships in elasticsearch?
推荐答案
没有办法建立多对多关系。
There's no way to model many-to-many relationships.
只有在每个帐户中存储每个组的ID,就像上面这样做。
The only way is to store the id of each group in each account like I have done so above.
弹性搜索效率非常高,所以经常是重新索引是一个可以接受的解决方案。此外,弹性搜索有文档的概念,而不是关系存储系统,因此可能永远不会实现多对多关系。
Elasticsearch is pretty efficient, so often times, reindexing is an acceptable solution. Also, elasticsearch has the notion of documents and is not a relational storage system, so many-to-many relationships would probably never be implemented.
这篇关于弹性搜索中的许多关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!