# Elasticsearch: OneToMany and ManyToOne not included in index

**URL:** https://discuss.elastic.co/t/elasticsearch-onetomany-and-manytoone-not-included-in-index/8021
**Category:** Elasticsearch
**Created:** [June 8, 2012, 1:28pm UTC](https://discuss.elastic.co/t/elasticsearch-onetomany-and-manytoone-not-included-in-index/8021 "2012-06-08T13:28:01Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![David\_3](https://avatars.discourse-cdn.com/v4/letter/d/eada6e/32.png) [@David\_3](https://discuss.elastic.co/u/David_3)
#### Post date: [June 8, 2012, 1:28pm UTC](https://discuss.elastic.co/t/elasticsearch-onetomany-and-manytoone-not-included-in-index/8021/1 "2012-06-08T13:28:01Z")

</div>

I have three play models which I want to index using elastic search.  
The first model - model1 - includes a List of type model2 with the  
following JPA mapping:  
@OneToMany(cascade = {CascadeType.ALL})

The second model includes a member variable of type model3 and the  
following JPA settings:  
@ManyToOne(fetch=FetchType.EAGER,optional=false)

The third model includes a List of type model2 with JPA following  
settings:  
@OneToMany(mappedBy="category", cascade = {CascadeType.ALL})

So it looks like this:

public class model1 extends Model{  
@OneToMany(cascade = {CascadeType.ALL})  
public List m2 = new ArrayList();  
}  
public class model2 extends Model{  
@ManyToOne(fetch=FetchType.EAGER,optional=false)  
public model3 m3;  
}  
public class model3 extends Model{  
@OneToMany(mappedBy="m3", cascade = {CascadeType.ALL})  
public List m2s;  
}

I am indexing existing data from a database by  
retrieving a list of JPA models for model1  
iterating over them and calling save.  
model1 and model2 are indexed successfully but the m2s member variable  
in model3 does not appear to be indexed properly. In the mashup UI (es-  
admin) the m2s field is listed but when I enter data nothing is  
displayed.

---

<div class="post-metadata">

### Author: ![David\_3](https://avatars.discourse-cdn.com/v4/letter/d/eada6e/32.png) [@David\_3](https://discuss.elastic.co/u/David_3)
#### Post date: [June 11, 2012, 11:45am UTC](https://discuss.elastic.co/t/elasticsearch-onetomany-and-manytoone-not-included-in-index/8021/2 "2012-06-11T11:45:27Z")

</div>

Does elasticsearch index the data of all objects referenced by the  
object you call save on?  
I am new to Elasticsearch so maybe there is a better approach to  
indexing linked data which I am missing.

I saw this post here which makes me think it does not but it is not  
the exact same scenario.  
[http://groups.google.com/group/elasticsearch/browse\_thread/thread/e61ffcb0421eb654/a7cf026802d102ee?lnk=gst&q=JOINS#a7cf026802d102ee](http://groups.google.com/group/elasticsearch/browse_thread/thread/e61ffcb0421eb654/a7cf026802d102ee?lnk=gst&q=JOINS#a7cf026802d102ee)

I think if it does not it will be a big reason for me not to use  
elasticsearch unless there is a workaround.

On Jun 8, 2:28 pm, David [davidrock...@gmail.com](mailto:davidrock...@gmail.com) wrote:

> I have three play models which I want to index using Elasticsearch.  
> The first model - model1 - includes a List of type model2 with the  
> following JPA mapping:  
> @OneToMany(cascade = {CascadeType.ALL})
> 
> The second model includes a member variable of type model3 and the  
> following JPA settings:  
> @ManyToOne(fetch=FetchType.EAGER,optional=false)
> 
> The third model includes a List of type model2 with JPA following  
> settings:  
> @OneToMany(mappedBy="category", cascade = {CascadeType.ALL})
> 
> So it looks like this:
> 
> public class model1 extends Model{  
> @OneToMany(cascade = {CascadeType.ALL})  
> public List m2 = new ArrayList();}
> 
> public class model2 extends Model{  
> @ManyToOne(fetch=FetchType.EAGER,optional=false)  
> public model3 m3;}
> 
> public class model3 extends Model{  
> @OneToMany(mappedBy="m3", cascade = {CascadeType.ALL})  
> public List m2s;
> 
> }
> 
> I am indexing existing data from a database by  
> retrieving a list of JPA models for model1  
> iterating over them and calling save.  
> model1 and model2 are indexed successfully but the m2s member variable  
> in model3 does not appear to be indexed properly. In the mashup UI (es-  
> admin) the m2s field is listed but when I enter data nothing is  
> displayed.

---

<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, 3:24am UTC](https://discuss.elastic.co/t/elasticsearch-onetomany-and-manytoone-not-included-in-index/8021/3 "2017-07-06T03:24:55Z")

</div>


