Elasticsearch DSL multi level nesting query not working

Hi ,

I am trying to write a multi level nested query in Elastic Search DSL. I am running into an issue where it says cannot create query.

This is a sample record:

{
"memory":123.989807,
"disks":[
{
"total":5033,
"name":"/",
"available":3437,
"used":1544,
"makers":[
{
"vendor":"a",
"place":"b"
},
{
"vendor":"c",
"place":"d"
}
]
},
{
"total":4057,
"name":"/dev",
"available":4057,
"used":0,
"makers":[
{
"vendor":"e",
"place":"f"
},
{
"vendor":"g",
"place":"h"
}
]
},
{
"total":4074,
"name":"/dev/shm",
"available":4074,
"used":0,
"makers":[
{
"vendor":"i",
"place":"j"
},
{
"vendor":"k",
"place":"l"
}
]
}
]
}

The query that i am trying to write in elasticsearch dsl:

es=Elasticsearch([{'host':'localhost','port':9200}])

request = elasticsearch_dsl.Search(using=es, index="multinested",doc_type='summary')
request = request.query('nested', path='disks', query=Q('nested', path='disks__makers', query=Q('match', disks__makers__vendor='a'), inner_hits={}), inner_hits={})

response=request.execute()

I was able to make it work in queries like this :

curl -X POST "localhost:9200/multinested/_search" -H 'Content-Type: application/json' -d'
{ "_source":false,
"query":{
"bool":{
"must":[
{
"nested":{
"path":"disks",
"query":{
"nested":{
"path":"disks.makers",
"query":{
"match":{
"disks.makers.vendor":"a"
}
},
"inner_hits":{}
}
},
"inner_hits":{}
}
}
]
}
}
}'

Any leads would be helpful

Resolved
Instead of underscore use period in the path.
request = request.query('nested', path='disks', query=Q('nested', path='disks_.makers',

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