Structure of the result is not readable

I have a 2 level nesting in my index. Like a nested object c inside a nested object b inside a flat object a . Now when I am applying a cross field search on nested and inner nested fields and using inner hits, I am getting very unsupported structure of data. And if I am applying query on just one nested object fields, then result is properly structured..

Is there any solution to this structure issue?

Can you show an example of the data, query and response? What is the mapping?

Can we have a single inner hits for multi level nesting?
As inner hits are only showing result for the queried part .

Hi This is the mapping used-

"mappings": {
"doc" : {
"dynamic": "strict",
"properties": {
"nameId": {
"type": "text",
"fields": {
"keyword" : {
"type": "keyword"
}
}},
"a": {
"type": "nested",
"properties": {
"aType": {
"type": "text",

            "fields": {
              "keyword": {
                "type": "keyword",
                "null_value": "null"
              }
            }
          },
          "aAmount":  {
            "type": "text",
           
            "fields": {
              "keyword": {
                "type": "keyword",
                "null_value": "null"
              },
              "integer":{
                "type": "integer"
              }
            }
            
            
          },
            "aDefault": {
            "type": "text",
            
            "fields": {
              "keyword": {
                "type": "keyword",
                "null_value": "null"
              }
            }
          },
            "b": {
             "type": "nested",
              "properties": {
                "bExpireDate": {
                  "type": "date",
                  "fields": {
                    "keyword": {
                      "type": "keyword",
                  "null_value": "null"
                      
                    }
                  }
                },
                "bAmount": {
                  "type": "text",
              "fields": {
                "keyword": {
                  "type": "keyword",
                  "null_value": "null"
                },
                "integer":{
                  "type": "integer"
                }
              }
                },
                "bCode": {
                  "type": "text",
                  "fields": {
                    "keyword": {
                      "type": "keyword",
                  "null_value": "null"
                      
                    }
                  }
                },
                "bBUID": {
                  "type": "text",
              "fields": {
                "keyword": {
                  "type": "keyword",
                  "null_value": "null"
                }
              }
                }
              }},
            "c": {
               "type": "nested",
              "properties": {
                "cExpireDate": {
                  "type": "date",
                  "fields": {
                    "keyword": {
                      "type": "keyword",
                  "null_value": "null"
                      
                    }
                  }
                },
                "cAmount": {
                  "type": "text",
              "fields": {
                "keyword": {
                  "type": "keyword",
                  "null_value": "null"
                },
                "integer":{
                  "type": "integer"
                }
              }
                },
                "cCode": {
                  "type": "text",
                  "fields": {
                    "keyword": {
                      "type": "keyword",
                  "null_value": "null"
                      
                    }
                  }
                },
                "cBUID": {
                  "type": "text",
              "fields": {
                "keyword": {
                  "type": "keyword",
                  "null_value": "null"
                }
              }
                }
            
              }
            }
    }
  }
}}}

}

This is the query used-
GET abc-demo/_search
{
"_source": false,
"query": {
"bool": {
"must": [
{
"nested": {
"path": "a",
"query": {
"bool": {
"must": [
{
"query_string": {
"default_field":
"a.aDefault",
"query": "No*"
}
},
{
"query_string": {
"fields": [
"a.aAmount"
],
"query": ""
}
},{
"query_string": {
"default_field":
"a.aType",
"query": "
"
}
} ]
}
},
"inner_hits": {
"size": 1,
"_source": {
"includes": [
"a.aAmount",
"a.aType",
"a.aDefault"
]
}
}
}
},
{ "bool": {
"should": [
{
"nested": {
"path": "a.b",
"query": {
"match": {
"a.b.bCode": "BPET"
}
},
"inner_hits": {
"size": 1,
"_source": {
"includes": [
"a.b.bCode"
]
}
}}
},
{
"nested": {
"path": "a.c",
"query": {

                          "match": {
                            "a.c.cCode": ""
                          }
                        },
                        "inner_hits": {
          "size": 1,
          "_source": {
            "includes": [
               "a.c.cCode"]

}} }} ] }} ]}}}

This is the output-

{
"took": 11,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 3.1823215,
"hits": [
{
"_index": "abc-demo",
"_type": "doc",
"_id": "2",
"_score": 3.1823215,
"inner_hits": {
"a": {
"hits": {
"total": 1,
"max_score": 3,
"hits": [
{
"_index": "abc-demo",
"_type": "doc",
"_id": "2",
"_nested": {
"field": "a",
"offset": 0
},
"_score": 3,
"_source": {
"a": {
"aAmount": "500",
"aType": "Contractor",
"aDefault": "no"
}
}
}
]
}
},
"a.b": {
"hits": {
"total": 2,
"max_score": 0.18232156,
"hits": [
{
"_index": "abc-demo",
"_type": "doc",
"_id": "2",
"_nested": {
"field": "a",
"offset": 0,
"_nested": {
"field": "b",
"offset": 1
}
},
"_score": 0.18232156,
"_source": {
"a": {
"b": {
"bCode": "BPET"
}
}
}
}
]
}
},
"a.c": {
"hits": {
"total": 0,
"max_score": null,
"hits":
}
}
}
}
]
}
}

Now my issue is , due to alot of bucket endings with brackets it is becoming very complex and difficult to integrate with angular as no. of loops seems to be infinite.. As this is a dummy index, i have alot of fields in my index and this is creating a problem.
Can we change the structure of output in a way that the parent nesting includes the child nesting with in the same bucket?

Thanks

Can we please have help in this case. This is crucial for me.

Please format your code, logs or configuration files using </> icon as explained in this guide and not the citation button. It will make your post more readable.

Or use markdown style like:

```
CODE
```

This is the icon to use if you are not using markdown format:

There's a live preview panel for exactly this reasons.

Lots of people read these forums, and many of them will simply skip over a post that is difficult to read, because it's just too large an investment of their time to try and follow a wall of badly formatted text.
If your goal is to get an answer to your questions, it's in your interest to make it as easy to read and understand as possible.
Please update your post.

You can't change the JSON generated by Elasticsearch. But you can add whatever application in the middle that changes the JSON generated by Elasticsearch to whatever format you want.

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