gpt4 book ai didi

many-to-many - Elasticsearch 中的多对多关系

转载 作者:行者123 更新时间:2023-11-29 02:47:13 28 4
gpt4 key购买 nike

我知道在elasticsearch中,我们可以有child/parent relationships文档之间。

然后,在建立索引时,我可以传递父 id,以便链接子文档和父文档:

$ curl -XPUT localhost:9200/blogs/blog_tag/1122?parent=1111 -d '{    "tag" : "something"}'

有没有在 elasticsearch 中模拟多对多关系的模型?

数据驻留在具有以下架构的 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.

目前这是我的 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')

这种方法的问题是,如果从索引中删除一个组,我将需要遍历每个帐户并从每个帐户中删除组 ID。这对我来说似乎有点低效。我还假设在使用 elasticsearch 的子/父关系时这不会成为问题。

有没有办法在 elasticsearch 中模拟多对多关系?

最佳答案

无法为多对多关系建模。

唯一的方法是将每个组的 ID 存储在每个帐户中,就像我在上面所做的那样。

Elasticsearch 非常高效,因此重建索引通常是一种可以接受的解决方案。另外,elasticsearch 有文档的概念,不是关系存储系统,所以多对多关系可能永远不会实现。

关于many-to-many - Elasticsearch 中的多对多关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11823287/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com