# Complex inner query

**URL:** https://discuss.elastic.co/t/complex-inner-query/238058
**Category:** Elastic Search
**Tags:** elastic-app-search
**Created:** [June 22, 2020, 9:59am UTC](https://discuss.elastic.co/t/complex-inner-query/238058 "2020-06-22T09:59:46Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Tornike\_Tarimanishvi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tornike_tarimanishvi/32/56310_2.png) [@Tornike\_Tarimanishvi](https://discuss.elastic.co/u/Tornike_Tarimanishvi)
#### Post date: [June 22, 2020, 9:59am UTC](https://discuss.elastic.co/t/complex-inner-query/238058/1 "2020-06-22T09:59:46Z")

</div>

Hello,  
Need help to create proper query for search, currently using Java API, even without java can't figure out how to do it wit elastic.

for example:  
i have two indexes followers and followings. each of them has same document model:  
`{ id:0, accountId:0, targetAccountId:0, targetName:String }`

i want to make search by name which searches into my followings index, next my followers index, next into followings of my followings and followesr of my followers.  
if found 20 records stop;

most embarrassing part is how to search in a single query all of this;  
i started searching in my follower and following documents name "John Doe" notthing found, how to tell elastic to continue searching into followers/followings of my followers/followings.

Thanks

---

<div class="post-metadata">

### Author: ![JasonStoltz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jasonstoltz/32/49893_2.png) [@JasonStoltz](https://discuss.elastic.co/u/JasonStoltz)
#### Post date: [July 1, 2020, 11:54am UTC](https://discuss.elastic.co/t/complex-inner-query/238058/2 "2020-07-01T11:54:02Z")

</div>

Hey @Tornike_Tarimanishvi, are you using Elasticsearch or Elastic App Search?

---

<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 29, 2020, 11:54am UTC](https://discuss.elastic.co/t/complex-inner-query/238058/3 "2020-07-29T11:54:07Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
