I know that in elasticsearch, we can have child/parent relationships between documents.
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?
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.
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')
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?