Hi ,
I have the following problem
Lets say I have a parent called parent-1 which has childs child-1(version:1,action:NOACTION),child-2(version:2,action:REVOKED) and child-3(version:3,action:CERTIFIED). Child 3 is the latest and currently active version.
Similarly I have another parent parent-2 with child-4 (version:1,action:NOACTION) and child-5(version:2,action:REVOKE) where child-5 is current and active version.
I want to pick the latest and currently active child document (child-3 and child-5) and aggregate them based on action taken.
My Final result should be
CERTIFY : 1
REVOKE : 1
Please let me know the approach to take.
Following are my mappings and data
put testparentchildnew
{
"mappings": {
"_doc": {
"properties": {
"prop1": {
"type": "keyword"
},
"prop2": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"doctype": {
"type": "keyword"
},
"childaction": {
"type": "keyword"
},
"childprop1": {
"type": "keyword"
},
"docversion" : {
"type" : "integer"
},
"childprop2": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"campaign_join_relation": {
"type": "join",
"relations": {
"parent": "child"
}
}
}
}
},
"settings": {
"index": {
"number_of_shards": 1,
"number_of_replicas": 1
}
}
}
post testparentchildnew/_doc/1
{
"prop1" : "parent1prop1",
"prop2" :"parent1prop2" ,
"doctype" : "parent",
"campaign_join_relation": {
"name" : "parent"
}
}
post testparentchildnew/_doc/2
{
"prop1" : "parent2prop1",
"prop2" :"parent2prop2" ,
"doctype" : "parent",
"campaign_join_relation": {
"name" : "parent"
}
}
-- child --
post testparentchildnew/_doc?routing=1
{
"childprop1" : "child1prop1",
"childprop2" :"child1prop2" ,
"childaction" : "NOACTION",
"docversion" : 1,
"doctype" : "child",
"campaign_join_relation": {
"name" : "child",
"parent" : "1"
}
}
post testparentchildnew/_doc?routing=1
{
"childprop1" : "child1prop1..",
"childprop2" :"child1prop2.." ,
"childaction" : "REVOKE",
"docversion" : 2,
"doctype" : "child",
"campaign_join_relation": {
"name" : "child",
"parent" : "1"
}
}
post testparentchildnew/_doc?routing=1
{
"childprop1" : "child1prop1..1",
"childprop2" :"child1prop2..1" ,
"childaction" : "CERTIFY",
"docversion" : 3,
"doctype" : "child",
"campaign_join_relation": {
"name" : "child",
"parent" : "1"
}
}
post testparentchildnew/_doc?routing=2
{
"childprop1" : "child2prop1",
"childprop2" :"child2prop2" ,
"childaction" : "NOACTION",
"docversion" : 2,
"doctype" : "child",
"campaign_join_relation": {
"name" : "child",
"parent" : "2"
}
}
post testparentchildnew/_doc?routing=2
{
"childprop1" : "child2prop1..",
"childprop2" :"child2prop2.." ,
"childaction" : "REVOKE",
"docversion" : 2,
"doctype" : "child",
"campaign_join_relation": {
"name" : "child",
"parent" : "2"
}
}