Say I have two indices like following
(Say Parent)
PUT dept?pretty
POST dept/department/_bulk
{"index":{"_id":"1"}}
{"Dept_ID":1,"Dept_name":"Engineering"}
{"index":{"_id":"2"}}
{"Dept_ID":2,"Dept_name":"Medical"}
(Say Child)
PUT dept_student?pretty
POST dept_student/dept/_bulk
{"index":{"_id":"1"}}
{"Emp_name":"Arya","Dept_ID":1,"Marks":150}
{"index":{"_id":"2"}}
{"Emp_name":"Banashree","Dept_ID":1,"Marks":200}
{"index":{"_id":"3"}}
{"Emp_name":"Arnab","Dept_ID":2,"Marks":120}
{"index":{"_id":"4"}}
{"Emp_name":"Abhirup","Dept_ID":2,"Marks":120}
I want to perform Parent child relationship.Please help me out..
Actually I want to build a report in kibana like following--
[Dept_Name] [Marks]
Engineering 350
Medical 240
PUT dept?pretty
POST /dept/department/_bulk
{"index":{"_id":"1"}}
{"Dept_ID":1,"Dept_name":"Engineering"}
{"index":{"_id":"2"}}
{"Dept_ID":2,"Dept_name":"Medical"}
PUT dept_student?pretty
POST /dept/dept_student/_bulk
{"index":{"_id":"100","parent":"1"}}
{"Emp_name":"Arya","Dept_ID":1,"Marks":150}
{"index":{"_id":"200","parent":"1"}}
{"Emp_name":"Banashree","Dept_ID":1,"Marks":200}
{"index":{"_id":"300","parent":"2"}}
{"Emp_name":"Arnab","Dept_ID":2,"Marks":120}
{"index":{"_id":"400","parent":"2"}}
{"Emp_name":"Abhirup","Dept_ID":2,"Marks":120}
Getting the below error msg...
"index": {
"_index": "dept",
"_type": "dept_student",
"_id": "200",
"status": 400,
"error": {
"type": "illegal_argument_exception",
"reason": "can't specify parent if no parent field has been configured"
}
}
}been configured"
}
}
}
POST /dept/dept_student/_bulk
{"index":{"_id":"100","parent":"1"}}
{"Emp_name":"Arya","Dept_ID":1,"Dept_name":"Engineering","Marks":150}
{"index":{"_id":"200","parent":"1"}}
{"Emp_name":"Banashree","Dept_ID":1,"Dept_name":"Engineering","Marks":200}
{"index":{"_id":"300","parent":"2"}}
{"Emp_name":"Arnab","Dept_ID":2,"Dept_name":"Medical","Marks":120}
{"index":{"_id":"400","parent":"2"}}
{"Emp_name":"Abhirup","Dept_ID":2,"Dept_name":"Medical","Marks":120}
As Elasticsearch is not a relational system, the best way to work with it is often to denormalise data rather than try using parent-child or nested document to emulate a relational model.
I got your point,it's better to denormalise data.
But if I want to perform parent child relationship then could you please tell me the mistakes that I have made in my code?
Have you specified an appropriate mapping for you data? You will also need to make sure you have indexed data using routing as shown in the link I provided. You can not perform parent-child queries if this is not in place.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.