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": []
}
}
}
}
]
}