我尝试一个小例子
我创建一个映射
PUT /company
{
"mappings": {
"country": {},
"branch": {
"_parent": {
"type": "country"
}
},
"employee": {
"_parent": {
"type": "branch"
}
}
}
}
并添加一些项目
POST /company/country/_bulk
{"index": {"_id": "countryA"}}
{"name": "0001"}
{"index": {"_id": "countryB"}}
{"name": "0008"}
{"index": {"_id": "countryC"}}
{"name": "0015"}
POST /company/branch/_bulk
{ "index": { "_id": "branchA", "parent": "countryA" }}
{ "name": "0002" }
{ "index": { "_id": "branchB", "parent": "countryA" }}
{ "name": "0005" }
{ "index": { "_id": "branchA", "parent": "countryB" }}
{ "name": "0009" }
{ "index": { "_id": "branchB", "parent": "countryB" }}
{ "name": "0012" }
{ "index": { "_id": "branchA", "parent": "countryC" }}
{ "name": "0016" }
{ "index": { "_id": "branchB", "parent": "countryC" }}
{ "name": "0019" }
但是,然后我运行请求
GET /company/branch/_search
结果只有 4 项分支
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 4,
"max_score": 1,
"hits": [
{
"_index": "company",
"_type": "branch",
"_id": "branchA",
"_score": 1,
"_routing": "countryC",
"_parent": "countryC",
"_source": {
"name": "0016"
}
},
{
"_index": "company",
"_type": "branch",
"_id": "branchB",
"_score": 1,
"_routing": "countryC",
"_parent": "countryC",
"_source": {
"name": "0019"
}
},
{
"_index": "company",
"_type": "branch",
"_id": "branchA",
"_score": 1,
"_routing": "countryB",
"_parent": "countryB",
"_source": {
"name": "0009"
}
},
{
"_index": "company",
"_type": "branch",
"_id": "branchB",
"_score": 1,
"_routing": "countryB",
"_parent": "countryB",
"_source": {
"name": "0012"
}
}
]
}
}
为什么,丢失了一对 countryA-branchA 和 countryA-branchB?
ps: 有时间再试试,可能是countryA和countryB冲突