# Nested/join scripted queries

**URL:** https://discuss.elastic.co/t/nested-join-scripted-queries/51742
**Category:** Elasticsearch
**Created:** [June 2, 2016, 8:36pm UTC](https://discuss.elastic.co/t/nested-join-scripted-queries/51742 "2016-06-02T20:36:15Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Fryder](https://avatars.discourse-cdn.com/v4/letter/f/76d3ee/32.png) [@Fryder](https://discuss.elastic.co/u/Fryder)
#### Post date: [June 2, 2016, 8:36pm UTC](https://discuss.elastic.co/t/nested-join-scripted-queries/51742/1 "2016-06-02T20:36:15Z")

</div>

Hello, I have a situation to write search query in elasticsearch having data as follows

```
{id:"p1",person:{name:"name",age:"12"},relatedTO:{id:"p2"}}
{id:"p2",person:{name:"name2",age:"15"},relatedTO:{id:"p3"}}
{id:"p3",person:{name:"name3",age:"17"},relatedTO:{id:"p1"}}

```

scenario:- user's want to search people related to p2,and using each related person find who they are related to

1.first find who are related to p2 answer= p1   
  
2.Now find people related to p1 answer=p3. _(the requirement as of now is to go only 1-level)_ so no need to find people related to p3.the final result should be p2,p1,p3.   
  
Normal scenario's we will write a nested sql to get results.How do we achieve this using elastic query language in one-shot

---

<div class="post-metadata">

### Author: ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)
#### Post date: [June 3, 2016, 8:48am UTC](https://discuss.elastic.co/t/nested-join-scripted-queries/51742/2 "2016-06-03T08:48:59Z")

</div>

In terms of exploring connections between people you might find the recent blog post on the Graph plugin and Panama papers of interest: [http://goo.gl/fbJy8D](http://goo.gl/fbJy8D)

---

<div class="post-metadata">

### Author: ![Fryder](https://avatars.discourse-cdn.com/v4/letter/f/76d3ee/32.png) [@Fryder](https://discuss.elastic.co/u/Fryder)
#### Post date: [June 3, 2016, 7:26pm UTC](https://discuss.elastic.co/t/nested-join-scripted-queries/51742/3 "2016-06-03T19:26:11Z")

</div>

Thanks for the info ,does graph has query search capability instead of graphical interface?  
or i want to explore is there any scripted query for my scenario  
as ppl are suggesting to go to neo4j.

---

<div class="post-metadata">

### Author: ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)
#### Post date: [June 3, 2016, 8:17pm UTC](https://discuss.elastic.co/t/nested-join-scripted-queries/51742/4 "2016-06-03T20:17:50Z")

</div>

Yep, API details here: [https://www.elastic.co/guide/en/graph/current/graph-api-rest.html](https://www.elastic.co/guide/en/graph/current/graph-api-rest.html)

---

<div class="post-metadata">

### Author: ![Fryder](https://avatars.discourse-cdn.com/v4/letter/f/76d3ee/32.png) [@Fryder](https://discuss.elastic.co/u/Fryder)
#### Post date: [June 10, 2016, 3:17pm UTC](https://discuss.elastic.co/t/nested-join-scripted-queries/51742/5 "2016-06-10T15:17:58Z")

</div>

sorry for late reply, i have dome some reading on this,as of now am doing application side joins(i mean multiple queries ) but will explore more on thi sin future

---

<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 5, 2017, 10:44pm UTC](https://discuss.elastic.co/t/nested-join-scripted-queries/51742/6 "2017-07-05T22:44:42Z")

</div>


