Elasticsearch 5.3 indexing issue: Children sometimes wind up on different shards than their parent after indexing. This prevents the use of hasChild and hasParent queries against the index.
The index (myindex_v001) contains three types: tasks, documents, assignments. When creating the index, documents are mapped as children of tasks, and assignments are mapped as children of documents.
{
"myindex_v001": {
"mappings": {
"tasks": {
"_all": {
"analyzer": "default",
"search_analyzer": "default_search"
},
...
}
{
"myindex_v001": {
"mappings": {
"documents": {
"_all": {
"analyzer": "default",
"search_analyzer": "default_search"
},
"_parent": {
"type": "tasks"
},
"_routing": {
"required": true
},
...
}
{
"myindex_v001": {
"mappings": {
"assignments": {
"_all": {
"analyzer": "default",
"search_analyzer": "default_search"
},
"_parent": {
"type": "documents"
},
"_routing": {
"required": true
},
...
}
All indexing is performed within a Java service. Java makes a REST call (PUT) to the url specifying the index, type, and parent_id. The same code is used to perform indexing on tasks, documents, and assignments.
When indexing documents (http://eshost:port/myindex/documents/{document_id}?parent={task_id}) each indexed document winds up on the same shard as its parent task as expected. hasChild queries work just fine for tasks/documents.
However, when indexing assignments (http://eshost:port/myindex/assignments/{assignment_id}?parent={document_id}) the assignment usually winds up being indexed on a shard that is different from its parent document. This is causing problems because a hasChild and hasParent query does not work with documents/assignments.
Can anyone suggest what may be going wrong with indexing the assignments (not being placed on same shard as documents)?