The following library helps you get a unified result with parents having result of children in a single result with scroll and custom query.
npm install esgetfamily --save
npm install esgetfamily
var esgetfamily = require('esgetfamily');
esgetfamily(
'http://localhost:9200',
{
index: 'es-getfamilytest',
parent_type: 'parent',
child_type: 'child'
},
[
{
_index: 'es-getfamilytest',
_type: 'parent',
_id: '1',
_score: 1,
_source: {
id: 1,
no_employee: 23,
company: 'Plotlabs'
}
}
],
[
{
match: {
employee_name: 'employee 1'
}
}
],
function(error, result) {
// Do something here.
}
);
The function takes following arguments and in the following order
esgetfamily(
< URL >,
< connection parameters>,
< data >,
< filter >,
function(error, result){
// Do something here.
}
);
- URL: Mention the URL of either localhost or remote server
- connection parameters: The argument has three parts
{ index: "name of the index", parent_type: "name of the parent type", children_type: "name of the children type" }
- data: pass any data array of parent object/objects. '_id' in each object is essential for it to parse it's child
- filter: you can pass any valid query object for eg.
[{match: { "employee_name":"employee 1" }}]
- callback: simple callback function with error as first argument
The result are in the form:
[
{
"_index": "es-getfamilytest",
"_type": "parent",
"_id": "1",
"_score": 1,
"_source": { "id": 1, "no_employee": 23, "company": "Plotlabs" },
"children": [
{
"_index": "es-getfamilytest",
"_type": "child",
"_id": "1",
"_score": 1,
"_routing": "1",
"_parent": "1",
"_source": { "id": 1, "name": "employee1" }
}
]
}
]