What's the difference of inling account information into a study and inlining the study into the doc.account.
The difference is that there is just one account per study document. To aggregate correctly in Kibana you have to provide the thing you want to aggregate over as a single document (without an array).
Currently your data looks like this:
{
key1: 1,
nested: [
{ nestedKey1: 2, nestedKey2: 3, },
{ nestedKey1: 4, nestedKey2: 5, },
{ nestedKey1: 6, nestedKey2: 7 },
]
}
If you want to do aggregation on the nested keys, you should instead create three documents like this:
{ key1: 1, nestedKey1: 2, nestedKey2: 3 },
{ key1: 1, nestedKey1: 4, nestedKey2: 5 },
{ key1: 1, nestedKey1: 6, nestedKey2: 7 }
Using kquery I can query the data comments.studies.study_id:6572436
(would return a result). I can't use studies
to aggregate, but I can use comments.date etc
If you look into your mapping, "comments" is probably not using a nested type, but "studies" is. You can change your mapping and not make "studies" nested, but that would probably not what you want, because in this case Elasticsearch is flattening the data in the array and the association between the values in the nested object is lost. E.g.
{
key1: 1,
nested: [
{ nestedKey1: 2, nestedKey2: 3, },
{ nestedKey1: 4, nestedKey2: 5, },
{ nestedKey1: 6, nestedKey2: 7 },
]
}
becomes
{
key1: 1,
nested.nestedKey1: [2, 4, 6],
nested.nestedKey2: [3, 5, 7],
}
and Elasticsearch won't know anymore that nestedKey1: 2
appeared together with nestedKey2: 3
in the same object. If you are insetad splitting up the document into three documents, you won't have that problem.