Search code examples
pythonelasticsearchelasticsearch-dslelasticsearch-queryelasticsearch-dsl-py

create query on subfield (field contained in another field) using elasticsearch-dsl-py?


similar to question I want to create a query on a sub field (which is not of type nested)

if data is in format

"fs": {
    "used": 1000,
    "mount_point": "/"
 }

as mentioned in answer by aaronfay I tried querying with

search.query('match', **{"fs.used": 0})

and it works as expected.

But for field named mount_point, the query returns empty response.

search.query('match', **{"fs.mount_point": "/"})

even if i have data which has mount_point = '/'. why?


Solution

  • What is your mappings for the mount_point field? You need that field to be of type keyword which means without any analyzer. By default it would be text which means it would be split into words and / is not a word so it would get dropped.