# Query index with multiple childs

**URL:** https://discuss.elastic.co/t/query-index-with-multiple-childs/170313
**Category:** Elasticsearch
**Created:** [February 28, 2019, 10:12am UTC](https://discuss.elastic.co/t/query-index-with-multiple-childs/170313 "2019-02-28T10:12:20Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![xavi23](https://avatars.discourse-cdn.com/v4/letter/x/db5fbb/32.png) [@xavi23](https://discuss.elastic.co/u/xavi23)
#### Post date: [February 28, 2019, 10:12am UTC](https://discuss.elastic.co/t/query-index-with-multiple-childs/170313/1 "2019-02-28T10:12:21Z")

</div>

Hi,

I want know how do a query to can get in the same document all information about same ID.

I've three indexs: hdm-paciente, hdm-diagnostics and hdm-cites. I create an index pattern hdm-\*.

In each index I've different information but finally I need to get all information about same ID (nhc) in the same query.

I use a Join Datatype to do this but I'm not sure what I'm doing wrong...

[https://www.elastic.co/guide/en/elasticsearch/reference/6.0/parent-join.html](https://www.elastic.co/guide/en/elasticsearch/reference/6.0/parent-join.html)

This is all scripts that I try todo:

PUT hdm-paciente  
{  
"mappings": {  
"hdm-paciente": {  
"properties": {  
"AGRUPACION": {  
"type": "join",  
"relations": {  
"PACIENTE": ["DIAGNOSTICS","CITES"]  
}  
},  
"nombre":{  
"type":"text"  
},  
"nhc":{  
"type":"integer"  
}  
}  
}  
}  
}

PUT hdm-diagnostics  
{  
"mappings": {  
"hdm-diagnostics": {  
"properties": {  
"AGRUPACION": {  
"type": "join",  
"relations": {  
"PACIENTE": ["DIAGNOSTICS","CITES"]  
}  
},  
"DIAGNOSTICS":{  
"type":"nested",  
"properties":{  
"VALOR":{  
"type":"text"  
},  
"nhc":{  
"type":"integer"  
}  
}  
}  
}  
}  
}  
}

PUT hdm-cites  
{  
"mappings": {  
"hdm-cites": {  
"properties": {  
"AGRUPACION": {  
"type": "join",  
"relations": {  
"PACIENTE": ["DIAGNOSTICS","CITES"]  
}  
},  
"CITES":{  
"type":"nested",  
"properties":{  
"VALOR\_CITA":{  
"type":"text"  
},  
"nhc":{  
"type":"integer"  
}  
}  
}  
}  
}  
}  
}

PUT hdm-paciente/hdm-paciente/12345?routing=1  
{  
"nombre": "Maria",  
"nhc":12345,  
"AGRUPACION": "PACIENTE"  
}

PUT hdm-paciente/hdm-paciente/666  
{  
"nombre": "Antonio",  
"nhc":666,  
"AGRUPACION": "PACIENTE"  
}

//// It is required to index the lineage of a parent in the same shard  
// so you must always route child documents using their greater parent id.

PUT hdm-diagnostics/hdm-diagnostics/12345?routing=1  
{  
"DIAGNOSTICS":[  
{  
"VALOR":"Fiebre",  
"nhc":12345  
},  
{  
"VALOR":"Acantosis",  
"nhc":12345  
}

],  
"AGRUPACION": {  
"name": "DIAGNOSTICS",  
"parent": "12345"  
}  
}

PUT hdm-cites/hdm-cites/12345?routing=1  
{  
"CITES":[  
{  
"VALOR\_CITA":"Fiebre",  
"nhc":12345  
},  
{  
"VALOR\_CITA":"Acantosis",  
"nhc":12345  
}

],  
"AGRUPACION": {  
"name": "CITES",  
"parent": "12345"  
}  
}

PUT hdm-diagnostics/hdm-diagnostics/666?routing=1  
{  
"DIAGNOSTICS":[  
{  
"VALOR":"Fiebre",  
"nhc":666  
},  
{  
"VALOR":"Acantosis",  
"nhc":666  
}

],  
"AGRUPACION": {  
"name": "DIAGNOSTICS",  
"parent": "666"  
}  
}

GET hdm-\*/\_search  
{  
"query": {  
"has\_parent": {  
"parent\_type": "PACIENTE",  
"query":{  
"match\_all":{

```
          }
        }
  }
}

```

}

The output that I should get is this:

"\_source": {  
"CITES": [  
{  
"VALOR\_CITA": "Fiebre",  
"nhc": 12345  
},  
{  
"VALOR\_CITA": "Acantosis",  
"nhc": 12345  
}  
],  
"AGRUPACION": {  
"name": "CITES",  
"parent": "12345"  
},  
"DIAGNOSTICS":[  
{  
"VALOR":"Fiebre",  
"nhc":12345  
},  
{  
"VALOR":"Acantosis",  
"nhc":12345  
}

],  
"AGRUPACION": {  
"name": "DIAGNOSTICS",  
"parent": "12345"  
},  
"nombre": "Maria",  
"nhc":12345,  
"AGRUPACION": "PACIENTE"  
}

Thanks for advanced.

King regards.

---

<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: [March 28, 2019, 10:12am UTC](https://discuss.elastic.co/t/query-index-with-multiple-childs/170313/2 "2019-03-28T10:12:23Z")

</div>

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