Search code examples
elasticsearchelasticsearch-dsl

What's the functionality of "path" in ES_dsl.Q()?


I have a statement: ES_dsl.Q('nested', path='student', query=nest_filter) What kind of role does the "path" play in the above one?


Solution

  • The path is simply the path to the nested field you're using in your query.

    In nest_filter, you need to reference your nested field as student.xyz.

    Check the equivalence in the query below:

    GET /_search
    {
        "query": {
            "nested" : {
                "path" : "student",           <--- this is the path
                "query" : {                   <--- this is nest_filter
                    "bool" : {
                        { "match" : {"student.name" : "john"} },
                        { "range" : {"student.age" : {"gt" : 20}} }
                        ]
                    }
                }
            }
        }
    }