Nested/join scripted queries

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

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

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.

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

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