I want to get only nested fields, but cannot since it's not leaf fields.
GET index/_search
{
    "size": 10,
    "fields": [
       "nested_fields"
    ]
}
ERROR : "reason": "field [nested_fields] isn't a leaf field"
I tried below but cannot match each id and name in nested object.
GET index/_search
    {
        "size": 10,
        "fields": [
           "nested_fields.id",
           "nested_fields.name"
        ]
    }
result :
"fields": {
               "events.id": [
                  "13342",
                  "24232",
                  "25534",
                  "63454"
               ],
               "events.name": [
                  "R1413",
                  "R1414",
                  "R1415",
                  "R1416",
               ]
            }
Here is my expected result:
fields" : {
  "evets" : {
      "id" : "234234",
      "name" : "RP1524"
   },
    .... so on
}
                The nested type is a specialised version of the object data type that allows arrays of objects to be indexed in a way that they can be queried independently of each other.
When a packed class contains an instance field that is a packed type, the data for that field is packed directly into the containing class. The field is known as a nested field .
Nested data types are structured data types for some common data patterns. Nested data types support structs, arrays, and maps. A struct is similar to a relational table. It groups object properties together.
If you don't have a certain query that should match the nested fields somehow, you can do it like this:
GET /index/_search
{
  "size": 10,
  "_source": ["nested_fields.id", "nested_fields.name"]
}
If you also have a nested query and you want to return the nested docs that matched you can do it like this (with inner_hits):
{
  "query": {
    "nested": {
      "path": "nested_fields",
      "query": {"match_all": {}}, 
      "inner_hits": {}
    }
  }
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With