Issue 1:
I am trying to model a employee hierarchy where every employee can be a manager of a team of employees and, at the same time, she can be part of a team managed by other employee:

curl -XPOST 'http://localhost:9200/manager_employee' -d '{

"mappings": {

"employee": {

"_parent": {

"type": "employee"

},

"properties": {

"name": {

"type": "string"

}

}

}

}

}'

The problem is when modeling a employee which is not managed by anyone (let's think about the CEO). I tried both alternatives bellow:

curl -s -XPOST localhost:9200/_bulk --data-binary '

{ "index" : { "_index" : "manager_employee", "_type" : "employee", "_id" : "employee1" , _parent:"employee1"} }

{ "name" : "chris"}

{ "index" : { "_index" : "manager_employee", "_type" : "employee", "_id" : "employee2" , _parent:"employee1"} }

{ "name" : "joseph" }

{ "index" : { "_index" : "manager_employee", "_type" : "employee", "_id" : "employee3" , _parent:"employee1"} }

{ "name" : "john" }'

i.e., the CEO is managed by herself and

curl -s -XPOST localhost:9200/_bulk --data-binary '

{ "index" : { "_index" : "manager_employee", "_type" : "employee", "_id" : "employee1" , _parent:"dummyID1"} }

{ "name" : "chris"}

{ "index" : { "_index" : "manager_employee", "_type" : "employee", "_id" : "employee2" , _parent:"employee1", _routing:"dummyID1"} }

{ "name" : "joseph" }

{ "index" : { "_index" : "manager_employee", "_type" : "employee", "_id" : "employee3" , _parent:"employee1", _routing:"dummyID1"} }

{ "name" : "john" }'

the CEO is managed by some dummy manager

In both cases:

curl -XGET 'localhost:9200/manager_employee/employee/_search' -d '{

"filter" : {

"has_child" : {

"child_type" : "employee",

"query" : {

"term" : {

"employee.name" : "john"

}

}

}}}'

works returning chris, but the other side of the relations fails:

curl -XGET 'localhost:9200/manager_employee/employee/_search' -d '{

"filter" : {

"has_parent" : {

"parent_type" : "employee",

"query" : {

"term" : {

"employee.name" : "chris"

}

}

}}}'

returns an empty hit set.

Is there any other way (without defining different) types of implementing this? Any workaround? Is it a bug that the relation is correctly mapped from children to parent but not from parent to children when using the same type in both sides of the relation?

Thank you in advance,

Issue 2:
We don't explicitly prohibit types from referring to themselves as parents. This functionality worked fine before 0.90 release, but since 0.90 it seems to be broken for the has_parent query. In the following script, both search requests return results in 0.20.x but only the second search request returns results in 0.90.x and above.

curl -XDELETE localhost:9200/test-idx
curl -XPUT localhost:9200/test-idx -d '{
"settings": {
"index.number_of_shards": 1,
"index.number_of_replicas": 0
},
"mappings": {
"doc": {
"_parent": {
"type": "doc"
}
}
}
}'
curl -XPUT "localhost:9200/test-idx/doc/1?routing=1&pretty" -d '{"name": "doc_1"}'
curl -XPUT "localhost:9200/test-idx/doc/2?parent=1&pretty" -d '{"name": "doc_2"}'
curl -XPOST "localhost:9200/test-idx/_refresh?pretty"
echo
curl "localhost:9200/test-idx/doc/_search?pretty" -d '{
"query": {
"has_parent": {
"type": "doc",
"query" : {
"match_all": {
}
}
}
}
}'
echo
curl "localhost:9200/test-idx/doc/_search?pretty" -d '{
"query": {
"has_child": {
"type": "doc",
"query" : {
"match_all": {
}
}
}
}
}'

search result in 0.20.6:

{
"took" : 54,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 1.0,
"hits" : [ {
"_index" : "test-idx",
"_type" : "doc",
"_id" : "2",
"_score" : 1.0, "_source" : {"name": "doc_2"}
} ]
}
}
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 1.0,
"hits" : [ {
"_index" : "test-idx",
"_type" : "doc",
"_id" : "1",
"_score" : 1.0, "_source" : {"name": "doc_1"}
} ]
}
}

search result in the current master:

{
"took" : 66,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"hits" : {
"total" : 0,
"max_score" : null,
"hits" : [ ]
}
}

{
"took" : 16,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 1.0,
"hits" : [ {
"_index" : "test-idx",
"_type" : "doc",
"_id" : "1",
"_score" : 1.0,
"_source":{"name": "doc_1"}
} ]
}
}