Help me to query this document

This is my documents:

//document 1
{
    "place": "galaxy",
    "range": {
        "area": {
            "planet": "mars",
            "country": [

              -----------country 1------------------

                {
                    "name": "mars-country_1",
                    "use_by": "alien",
                    "region": [ 
   
             -------region 1--------

                        {
                            "name": "ABC",
                            "value": "ABC"
                        },

             -------region 2--------

                        {
                            "name": "DEF",
                            "value": "DEF"
                        }
                    ]
                },

              -----------country 2------------------

                {
                    "name": "mars-country_2",
                    "use_by": "alien_2",
                    "region": [
                        {
                            "name": "ABC",
                            "value": "ABC"
                        },
                        {
                            "name": "DEF",
                            "value": "DEF"
                        }
                    ]
                }
              -----------country 3------------------
              -----------country 4------------------
            ]
        }
    }
}
//document 2
//document 3

Now if I provide country name and region name: "mars-country_1" and "ABC", the result will:

                {
                    "name": "mars-country_1",
                    "use_by": "alien",
                    "region": [
                        {
                            "name": "ABC",
                            "value": "ABC"
                        }
                    ]
                }

How can I do that, I do not know how to query in this case. Can anyone help me? Many thanks

Welcome!

You can't really get that as a result as the full document you indexed will be returned.

But the question is: what are you searching for? A region?

If you are searching for region, you should index regions instead. So denormalize your data. It will make your life easier.

1 Like

Have a look at this: Retrieve inner hits | Elasticsearch Guide [8.9] | Elastic

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