Index documents with autogenerated ID and custom routing

I want to index documents with an autogenerated ID and a Routing.
The ID field is autogenerated, so I want to link a parent to a child by ExternalId.

I use NEST client for .NET and have such a piece of code:

 await _elasticClient.BulkAsync(b => b
                .IndexMany(estimateDocuments, (descriptor, estimate) => descriptor
                    .Routing(estimate.ExternalId)
                    .Id(estimate.Id)
                    .Index(_elasticSearch.EstimateIndex)
                )
                .Refresh(Elasticsearch.Net.Refresh.True)

                .IndexMany(estimateCustomers, (descriptor, customer) => descriptor
                    .Routing(customer.Parent)
                    .Id(customer.Id)
                    .Index(_elasticSearch.EstimateIndex)
                )
                .Refresh(Elasticsearch.Net.Refresh.True)
);

It's ok. But now, I can't get an estimate with a customer.
Here is my query:

{
    "query": {
        "bool": {
            "must": [
                {
                    "match": {
                        "number": "5785"
                    }
                },
                {
                    "has_child": {
                        "type": "customer",
                        "query": {
                            "match_all": {}
                        },
                        "inner_hits": {}
                    }
                }
            ]
        }
    }
}

This is a result:

    "hits": {
        "total": {
            "value": 1,
            "relation": "eq"
        },
        "max_score": 0.9808291,
        "hits": [
            {
                "_index": "estimate-index",
                "_type": "_doc",
                "_id": "SVwAhnYBf45xwI3rMoDn",
                "_score": 0.9808291,
                "_routing": "699f0ab9-248f-44f8-9192-000fe61fd2cd",
                "_source": {
                    "number": "5785",
                    "externalId": "699f0ab9-248f-44f8-9192-000fe61fd2cd",
                    "joinField": "estimate"
                },
                "inner_hits": {
                    "item": {
                        "hits": {
                            "total": {
                                "value": 0,
                                "relation": "eq"
                            },
                            "max_score": null,
                            "hits": []
                        }
                    },
                    "customer": {
                        "hits": {
                            "total": {
                                "value": 0,
                                "relation": "eq"
                            },
                            "max_score": null,
                            "hits": []
                        }
                    }
                }
            }
        ]
    }

If you are using parent-child relationships the parent and child documents must reside in the same shard and therefore need to use the same routing value.

Both routings settings (ExternalId and Parent) are the same. And they have to be in the same shard.

Please provide documents, mappings and queries required to reproduce this in the Kibana development console. I do not know the NEST client and am not a .NET developer.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.