Hello,
Yes, you can do as follows (which I think is the order of operations you described):
PUT test_join
{
"settings": {
"number_of_replicas": 0,
"number_of_shards": 1
},
"mappings": {
"properties": {
"text": {
"type": "text"
},
"joint": {
"type": "join",
"relations": {
"group": "person"
}
}
}
}
}
# index a Group
PUT test_join/_doc/1?refresh
{
"text": "First day group",
"joint": "group"
}
# index a Person belonging to the Group
PUT test_join/_doc/2?routing=1&refresh
{
"text": "Person who will move",
"joint": {
"name": "person",
"parent": "1"
}
}
# Delete the group
DELETE test_join/_doc/1
# Create the new Group
PUT test_join/_doc/3?refresh
{
"text": "Second day group",
"joint": "group"
}
# Reindex the Person (update would work, too)
PUT test_join/_doc/2?routing=3&refresh
{
"text": "Person who will move",
"joint": {
"name": "person",
"parent": "3"
}
}
Now let's do some basic validation:
# check the Person doc by GET
GET test_join/_doc/2
{
"_index" : "test_join",
"_type" : "_doc",
"_id" : "2",
"_version" : 2,
"_seq_no" : 4,
"_primary_term" : 1,
"_routing" : "3",
"found" : true,
"_source" : {
"text" : "Person who will move",
"joint" : {
"name" : "person",
"parent" : "3"
}
}
}
# check the join by has_parent
GET /test_join/_search
{
"query": {
"has_parent": {
"parent_type": "group",
"query": {
"match": {
"text": "Second"
}
}
}
}
}
{
"took" : 21,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "test_join",
"_type" : "_doc",
"_id" : "2",
"_score" : 1.0,
"_routing" : "3",
"_source" : {
"text" : "Person who will move",
"joint" : {
"name" : "person",
"parent" : "3"
}
}
}
]
}
}
# check the join by has_child
GET /test_join/_search
{
"query": {
"has_child": {
"type": "person",
"query": {
"match": {
"text": "Person"
}
}
}
}
}
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "test_join",
"_type" : "_doc",
"_id" : "3",
"_score" : 1.0,
"_source" : {
"text" : "Second day group",
"joint" : "group"
}
}
]
}
}
These results are as intended by the operations.