# Joining queries across types and indexes

**URL:** <https://discuss.elastic.co/t/joining-queries-across-types-and-indexes/96359>\
**Category:** Kibana\
**Created:** [August 9, 2017, 1:51am UTC](https://discuss.elastic.co/t/joining-queries-across-types-and-indexes/96359 "2017-08-09T01:51:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![arunvijayam](https://avatars.discourse-cdn.com/v4/letter/a/ba9def/32.png) [@arunvijayam](https://discuss.elastic.co/u/arunvijayam)\
**Post date:** [August 9, 2017, 1:51am UTC](https://discuss.elastic.co/t/joining-queries-across-types-and-indexes/96359/1 "2017-08-09T01:51:03Z")

</div>

Hi All,

I have store customer, agent and customeragentmap as below,  
curl -XPUT "[http://localhost:9200/my\_index/customer/1?pretty](http://localhost:9200/my_index/customer/1?pretty)" -d "{ "firstname" : "deepan", "lastname" : "chandra", "customerid" : "c1"}"  
curl -XPUT "[http://localhost:9200/my\_index/customer/2?pretty](http://localhost:9200/my_index/customer/2?pretty)" -d "{ "firstname" : "siva", "lastname" : "suresh", "customerid" : "c2"}"  
curl -XPUT "[http://localhost:9200/my\_index/customer/3?pretty](http://localhost:9200/my_index/customer/3?pretty)" -d "{ "firstname" : "vaira", "lastname" : "muthu", "customerid" : "c3"}"  
curl -XPUT "[http://localhost:9200/my\_index/customer/4?pretty](http://localhost:9200/my_index/customer/4?pretty)" -d "{ "firstname" : "balaji", "lastname" : "badraraju", "customerid" : "c4"}"  
curl -XPUT "[http://localhost:9200/my\_index/customer/5?pretty](http://localhost:9200/my_index/customer/5?pretty)" -d "{ "firstname" : "deva", "lastname" : "subramani", "customerid" : "c5"}"  
curl -XPUT "[http://localhost:9200/my\_index/agent/1?pretty](http://localhost:9200/my_index/agent/1?pretty)" -d "{ "agentname" : "arun", "agentid" : "a2"}"  
curl -XPUT "[http://localhost:9200/my\_index/agent/2?pretty](http://localhost:9200/my_index/agent/2?pretty)" -d "{ "agentname" : "vanitha", "agentid" : "a4"}"  
curl -XPUT "[http://localhost:9200/my\_index/agent/3?pretty](http://localhost:9200/my_index/agent/3?pretty)" -d "{ "agentname" : "kisshor", "agentid" : "a6"}"  
curl -XPUT "[http://localhost:9200/my\_index/agent/4?pretty](http://localhost:9200/my_index/agent/4?pretty)" -d "{ "agentname" : "balaji", "agentid" : "a8"}"  
curl -XPUT "[http://localhost:9200/my\_index/agentcutomermap/1?pretty](http://localhost:9200/my_index/agentcutomermap/1?pretty)" -d "{ "customerid" : "c2", "agentid" : "a2"}"  
curl -XPUT "[http://localhost:9200/my\_index/agentcutomermap/2?pretty](http://localhost:9200/my_index/agentcutomermap/2?pretty)" -d "{ "customerid" : "c4", "agentid" : "a2"}"  
curl -XPUT "[http://localhost:9200/my\_index/agentcutomermap/3?pretty](http://localhost:9200/my_index/agentcutomermap/3?pretty)" -d "{ "customerid" : "c1", "agentid" : "a4"}"  
curl -XPUT "[http://localhost:9200/my\_index/agentcutomermap/4?pretty](http://localhost:9200/my_index/agentcutomermap/4?pretty)" -d "{ "customerid" : "c2", "agentid" : "a4"}"  
curl -XPUT "[http://localhost:9200/my\_index/agentcutomermap/5?pretty](http://localhost:9200/my_index/agentcutomermap/5?pretty)" -d "{ "customerid" : "c3", "agentid" : "a4"}"  
curl -XPUT "[http://localhost:9200/my\_index/agentcutomermap/6?pretty](http://localhost:9200/my_index/agentcutomermap/6?pretty)" -d "{ "customerid" : "c3", "agentid" : "a6"}"  
curl -XPUT "[http://localhost:9200/my\_index/agentcutomermap/7?pretty](http://localhost:9200/my_index/agentcutomermap/7?pretty)" -d "{ "customerid" : "c1", "agentid" : "a6"}"  
curl -XPUT "[http://localhost:9200/my\_index/agentcutomermap/8?pretty](http://localhost:9200/my_index/agentcutomermap/8?pretty)" -d "{ "customerid" : "c5", "agentid" : "a6"}"  
curl -XPUT "[http://localhost:9200/my\_index/agentcutomermap/9?pretty](http://localhost:9200/my_index/agentcutomermap/9?pretty)" -d "{ "customerid" : "c2", "agentid" : "a8"}"  
curl -XPUT "[http://localhost:9200/my\_index/agentcutomermap/10?pretty](http://localhost:9200/my_index/agentcutomermap/10?pretty)" -d "{ "customerid" : "c1", "agentid" : "a8"}"  
curl -XPUT "[http://localhost:9200/my\_index/agentcutomermap/11?pretty](http://localhost:9200/my_index/agentcutomermap/11?pretty)" -d "{ "customerid" : "c4", "agentid" : "a8"}"  
curl -XPUT "[http://localhost:9200/my\_index/agentcutomermap/12?pretty](http://localhost:9200/my_index/agentcutomermap/12?pretty)" -d "{ "customerid" : "c5", "agentid" : "a8"}"  
curl -XPUT "[http://localhost:9200/my\_index/agentcutomermap/13?pretty](http://localhost:9200/my_index/agentcutomermap/13?pretty)" -d "{ "customerid" : "c3", "agentid" : "a8"}"  
curl -XPUT "[http://localhost:9200/my\_index/agentcutomermap/14?pretty](http://localhost:9200/my_index/agentcutomermap/14?pretty)" -d "{ "customerid" : "c4", "agentid" : "a4"}"  
curl -XPUT "[http://localhost:9200/my\_index/agentcutomermap/18?pretty](http://localhost:9200/my_index/agentcutomermap/18?pretty)" -d "{ "customerid" : "c5", "agentid" : "a2"}"

Can anyone tell me how I write a query to fetch all customerid records from corresponding agentid and vise versa. The work around can be any way.

---

<div class="post-metadata">

**Author:** ![arunvijayam](https://avatars.discourse-cdn.com/v4/letter/a/ba9def/32.png) [@arunvijayam](https://discuss.elastic.co/u/arunvijayam)\
**Post date:** [August 9, 2017, 2:00am UTC](https://discuss.elastic.co/t/joining-queries-across-types-and-indexes/96359/2 "2017-08-09T02:00:38Z")

</div>

I want to take only customer records from having agentid

---

<div class="post-metadata">

**Author:** ![spalger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spalger/32/14092_2.png) [@spalger](https://discuss.elastic.co/u/spalger)\
**Post date:** [August 9, 2017, 11:36pm UTC](https://discuss.elastic.co/t/joining-queries-across-types-and-indexes/96359/3 "2017-08-09T23:36:18Z")

</div>

Are you trying to do this in Kibana? If you're looking for general advice on how to query elasticsearch I suggest the #elasticsearch category

---

<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:** [September 6, 2017, 11:36pm UTC](https://discuss.elastic.co/t/joining-queries-across-types-and-indexes/96359/4 "2017-09-06T23:36:24Z")

</div>

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