# Need some help for creating my model

**URL:** https://discuss.elastic.co/t/need-some-help-for-creating-my-model/16732
**Category:** Elasticsearch
**Created:** [April 1, 2014, 6:59am UTC](https://discuss.elastic.co/t/need-some-help-for-creating-my-model/16732 "2014-04-01T06:59:54Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Stefan\_Kruse](https://avatars.discourse-cdn.com/v4/letter/s/8baadc/32.png) [@Stefan\_Kruse](https://discuss.elastic.co/u/Stefan_Kruse)
#### Post date: [April 1, 2014, 6:59am UTC](https://discuss.elastic.co/t/need-some-help-for-creating-my-model/16732/1 "2014-04-01T06:59:54Z")

</div>

Hello, i am new to elasticsearch and i need some help/hints for creatine my  
model. For my relational database ( mysql ) is have the following situation:

Table: Subcategories  
Columns: Name, Company

Every subcategory has a name and has a 1:n company relation.

The next is:

Table: Company  
Columns: Name, Subcategory

Every company has a name and has a 1:n subcategory relation.

How can i modelling this for elasticsearch. I have a serach form with the  
following situation: The user can serach for subcategories, but only one  
should shown with have a company assigned. Then you select a subcategory  
and omitted the subcategory id. Then only companies should shown which are  
assigned to the subcategory.

For some hints i would be very thankfull.

Thanks

Stefan

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/53655a8b-46bc-4c95-8959-61831ac3d1c7%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/53655a8b-46bc-4c95-8959-61831ac3d1c7%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Binh\_Ly\_2](https://avatars.discourse-cdn.com/v4/letter/b/d07c76/32.png) [@Binh\_Ly\_2](https://discuss.elastic.co/u/Binh_Ly_2)
#### Post date: [April 1, 2014, 2:45pm UTC](https://discuss.elastic.co/t/need-some-help-for-creating-my-model/16732/2 "2014-04-01T14:45:16Z")

</div>

This might help:

> **[Managing Relations Inside Elasticsearch
	  	 | Elastic](https://www.elastic.co/blog/managing-relations-inside-elasticsearch)**
>
> Data in the real world is rarely simple - often times it is a jumble of interlocking relations. How do you represent relational data in Elasticsearch? There are a few mechanisms that can be used to pr...

Out of the box, you can't model many to many in ES (unless you do it  
yourself in code). One to many is supported using either nested or  
parent-child.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/159e41dd-32b6-4745-83a0-35f17eda0eda%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/159e41dd-32b6-4745-83a0-35f17eda0eda%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Stefan\_Kruse](https://avatars.discourse-cdn.com/v4/letter/s/8baadc/32.png) [@Stefan\_Kruse](https://discuss.elastic.co/u/Stefan_Kruse)
#### Post date: [April 2, 2014, 10:11am UTC](https://discuss.elastic.co/t/need-some-help-for-creating-my-model/16732/3 "2014-04-02T10:11:04Z")

</div>

Hello,

many thanks to your answer.  
Could you give me a little example how to add/remove a single child to a  
parent object, maybe.  
I would like to do this with the elasticsearch php module. Is this possible?

Regards Stefan

Am Dienstag, 1. April 2014 16:45:16 UTC+2 schrieb Binh Ly:

> This might help:
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/blog/managing-relations-inside-elasticsearch/)
> 
> Out of the box, you can't model many to many in ES (unless you do it  
> yourself in code). One to many is supported using either nested or  
> parent-child.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/3ff28df3-39ca-4e3c-b678-8c49f631473d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/3ff28df3-39ca-4e3c-b678-8c49f631473d%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Stefan\_Kruse](https://avatars.discourse-cdn.com/v4/letter/s/8baadc/32.png) [@Stefan\_Kruse](https://discuss.elastic.co/u/Stefan_Kruse)
#### Post date: [April 4, 2014, 5:56am UTC](https://discuss.elastic.co/t/need-some-help-for-creating-my-model/16732/4 "2014-04-04T05:56:40Z")

</div>

hm, a little example would be nice. I dont get it to run. Thanks-

Am Mittwoch, 2. April 2014 12:11:04 UTC+2 schrieb Stefan Kruse:

> Hello,
> 
> many thanks to your answer.  
> Could you give me a little example how to add/remove a single child to a  
> parent object, maybe.  
> I would like to do this with the elasticsearch php module. Is this  
> possible?
> 
> Regards Stefan
> 
> Am Dienstag, 1. April 2014 16:45:16 UTC+2 schrieb Binh Ly:
> 
> > This might help:
> > 
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/blog/managing-relations-inside-elasticsearch/)
> > 
> > Out of the box, you can't model many to many in ES (unless you do it  
> > yourself in code). One to many is supported using either nested or  
> > parent-child.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/0f0bbe95-b95d-4e3c-9434-060fe30a9e0a%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/0f0bbe95-b95d-4e3c-9434-060fe30a9e0a%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Binh\_Ly\_2](https://avatars.discourse-cdn.com/v4/letter/b/d07c76/32.png) [@Binh\_Ly\_2](https://discuss.elastic.co/u/Binh_Ly_2)
#### Post date: [April 4, 2014, 8:27pm UTC](https://discuss.elastic.co/t/need-some-help-for-creating-my-model/16732/5 "2014-04-04T20:27:51Z")

</div>

So assuming you want parent/child (assuming you already set up the mapping  
correctly), to add a child to a parent:

curl -XPOST localhost:9200/test/child/child1?parent=parent1 -d'  
{  
"state" : "Ohio"  
}'

To delete the above child:

curl -XDELETE localhost:9200/test/child/child1

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/9900330b-f1e3-432f-9e0b-5621d16899cc%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/9900330b-f1e3-432f-9e0b-5621d16899cc%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Stefan\_Kruse](https://avatars.discourse-cdn.com/v4/letter/s/8baadc/32.png) [@Stefan\_Kruse](https://discuss.elastic.co/u/Stefan_Kruse)
#### Post date: [April 11, 2014, 8:18am UTC](https://discuss.elastic.co/t/need-some-help-for-creating-my-model/16732/6 "2014-04-11T08:18:07Z")

</div>

Hi Binh Ly,

thanks for answer, That helped me a lot. But how can i use the same queries  
with the PHP API? I need to add the parent query, but i dont find anything  
about this in the docu.

Thanks for helping and sharing your time.

Regards Stefan

Am Freitag, 4. April 2014 22:27:51 UTC+2 schrieb Binh Ly:

> So assuming you want parent/child (assuming you already set up the mapping  
> correctly), to add a child to a parent:
> 
> curl -XPOST localhost:9200/test/child/child1?parent=parent1 -d'  
> {  
> "state" : "Ohio"  
> }'
> 
> To delete the above child:
> 
> curl -XDELETE localhost:9200/test/child/child1

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/30641aa3-02bf-4d82-9d50-331171c3d3d3%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/30641aa3-02bf-4d82-9d50-331171c3d3d3%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Stefan\_Kruse](https://avatars.discourse-cdn.com/v4/letter/s/8baadc/32.png) [@Stefan\_Kruse](https://discuss.elastic.co/u/Stefan_Kruse)
#### Post date: [April 14, 2014, 12:57pm UTC](https://discuss.elastic.co/t/need-some-help-for-creating-my-model/16732/7 "2014-04-14T12:57:35Z")

</div>

Maybe a short answer how i can use it with the php api? 🙂 1000 times thank  
you, Stefan

Am Freitag, 11. April 2014 10:18:07 UTC+2 schrieb Stefan Kruse:

> Hi Binh Ly,
> 
> thanks for answer, That helped me a lot. But how can i use the same  
> queries with the PHP API? I need to add the parent query, but i dont find  
> anything about this in the docu.
> 
> Thanks for helping and sharing your time.
> 
> Regards Stefan
> 
> Am Freitag, 4. April 2014 22:27:51 UTC+2 schrieb Binh Ly:
> 
> > So assuming you want parent/child (assuming you already set up the  
> > mapping correctly), to add a child to a parent:
> > 
> > curl -XPOST localhost:9200/test/child/child1?parent=parent1 -d'  
> > {  
> > "state" : "Ohio"  
> > }'
> > 
> > To delete the above child:
> > 
> > curl -XDELETE localhost:9200/test/child/child1

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/c1761a0d-7470-477e-ae78-97773051f47b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c1761a0d-7470-477e-ae78-97773051f47b%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Stefan\_Kruse](https://avatars.discourse-cdn.com/v4/letter/s/8baadc/32.png) [@Stefan\_Kruse](https://discuss.elastic.co/u/Stefan_Kruse)
#### Post date: [April 18, 2014, 1:43pm UTC](https://discuss.elastic.co/t/need-some-help-for-creating-my-model/16732/8 "2014-04-18T13:43:32Z")

</div>

Ok new try. Is it general possible to do this with the PHP API, i dont find nothing in the docu. Maybe i dont see it. Regards Stefan

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/deb41747-30d3-4e48-8bb3-86f861020560%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/deb41747-30d3-4e48-8bb3-86f861020560%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [July 6, 2017, 1:35am UTC](https://discuss.elastic.co/t/need-some-help-for-creating-my-model/16732/9 "2017-07-06T01:35:02Z")

</div>


