Query index with multiple childs

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

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.

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