Joining multiple document within same index with joining the key

Just have an question on query to join multiple document together.
For example , i have the following 6 document into same index:

{
"_id" : 1,
"studentId" : "a11",
"class" : "1A",
"classNumber" : 11
},
{
"_id" : 2,
"studentId" : "a11",
"hobby" :"swimming"
},
{
"_id" : 3,
"studentId" : "a11",
"Country" : "USA"
},
{
"_id" : 4,
"studentId" : "b22",
"class" : "1B",
"classNumber" : 50
},
{
"_id" : 5,
"studentId" : "b22",
"hobby" :"cooking"
},
{
"_id" : 6,
"studentId" : "c33",
"Country" : "USA"
}

May i know if i may use DSL query to join the document together based on a key (e.g. "studentId") and become like this?

{
"_id" : 1,
"studentId" : "a11",
"class" : "1A",
"classNumber" : 11
"hobby" :"swimming"
"Country" : "USA"
},
{
"_id" : 4,
"studentId" : "b22",
"class" : "1B",
"classNumber" : 50
"hobby" :"cooking"
},
{
"_id" : 6,
"studentId" : "c33",
"Country" : "USA"
}

Or i need to create a new index? Any other suggestion are welcome.

Elasticsearch does not support joins so I would recommend indexed by the data as you want to retrieve and query it.

what you mean is prepare the data first (deformalized it first) and put in index?

Yes.

But sometime we cannot deformalize it from the beginning . (e.g. they are insert in different timestamp by restful API). So in this case we need to and another layer to join it first before put in index? No other choice?

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