Nested object retrieval in ElasticSearch query

Hi, I'm new in ElasticSearch and I have a few questions regarding nested object retrieval when a specific condition is matched.

I have a tree-like structure as follow:

{

    "id": 4,
    "sora": [
        {
            "pContext": {
                "context": {
                    "sT": "D3",
                    "uT": "ST"
                },
                "entities": [
                    {
                        "name": "premium",
                        "bName": "premium",
                        "fT": "site",
                        "eT": "F_P",
                        "children": [
                            {
                                "name": "capa",
                                "bName": "capa",
                                "fT": "site",
                                "eT": "FFT",
                                "children": []
                            },
                            {
                                "name": "code",
                                "bName": "Codes",
                                "fT": "site",
                                "eT": "FFT",
                                "children": []
                            },
                            {
                                "name": "selection A",
                                "fT": "site",
                                "eT": "SELECTION_A",
                                "children": [
                                    {
                                        "name": "A1",
                                        "fT": "site",
                                        "eT": "ADD",
                                        "children": []
                                    },
                                    {
                                        "name": "A2",
                                        "fT": "site",
                                        "eT": "ADD",
                                        "children": []
                                    }
                                ]
                            }
                        ]
                    }
                ]
            }
        },
        {
            "pContext": {
                "context": {
                    "sT": "D2",
                    "uT": "ST"
                },
                "entities": [
                    {
                        "name": "112",
                        "bName": "112",
                        "eT": "D_TYPE",
                        "children": []
                    }
                ]
            }
        }
    ]
}

My mapping:

{
    "mappings": {
        "abc": {
            "properties": {
                "id": {
                    "type": "integer"
                },
                "sora": {
                    "type": "nested",
                    "properties": {
                        "pContext": {
                            "type": "nested",
                            "properties": {
                                "context": {
                                    "type": "nested",
                                    "properties": {
                                        "sT": {
                                            "type": "text"
                                        },
                                        "uT": {
                                            "type": "text"
                                        }
                                    }
                                },
                                "entities": {
                                    "type": "nested",
                                    "properties": {
                                        "name": {
                                            "type": "text"
                                        },
                                        "bName": {
                                            "type": "text"
                                        },
                                        "fT": {
                                            "type": "text"
                                        },
                                        "eT": {
                                            "type": "text"
                                        },
                                        "children": {
                                            "type": "object"                                    
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
  • What I would like to know is, how can I get the nested object that matches my query and their children. I need the object that matched the must inclusive filter. Is that possible?
  • How can I search for a field without specifying the path? E.g: "*.myfield": "value" and retrieve the nested object that matched it.

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