Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8374291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:53:31+00:00 2026-06-09T14:53:31+00:00

I know that in elasticsearch, we can have child/parent relationships between documents. And then,

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T14:53:32+00:00Added an answer on June 9, 2026 at 2:53 pm

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that you can store a bunch of Parent* objects in a vector.
I know that Java have its own garbage collection, but sometimes I want to
I know that I can hijack a form by showing a login form in
I know that immutable objects always have the same state, the state in which
I know that ads colors can be set up in account settings, but I
I know that, as of Java 1.5 , one can add a component to
I know that I can use virtual keyword to tell the entity framework that
I know that you can set the number of threads to use for all
I know that boxing/unboxing affects performance. According to MSDN, unboxing can take four times
I know that I can use System.getProperty(user.home) gets the default home for files and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.