Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 451 Vote(s) - 3.45 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Many to many relationships in elasticsearch

#1
I know that in elasticsearch, we can have [child/parent relationships][1] 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][2] 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?

[1]:

[To see links please register here]

[2]:

[To see links please register here]

Reply

#2
There's no way to model many-to-many relationships.

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.
Reply

#3

When you think of efficiency, what you need to consider is write-time vs read-time efficiency. Relational databases favour write-time efficiency, while NoSQL favours read-time efficiency.

You need to carefully consider the ratio of read vs write in your application, and determine what will be more efficient overall. In the end, something needs to do the work of joining all the relationships, either when the data is written, or when the data is read.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through