elasticsearch 为什么elasticsearch在索引后丢失项目?,elasticsearch,parent-child,sense,elasticsearch,Parent Child,Sense" /> elasticsearch 为什么elasticsearch在索引后丢失项目?,elasticsearch,parent-child,sense,elasticsearch,Parent Child,Sense" />

elasticsearch 为什么elasticsearch在索引后丢失项目?

elasticsearch 为什么elasticsearch在索引后丢失项目?,elasticsearch,parent-child,sense,elasticsearch,Parent Child,Sense,我正在尝试一个小例子 我创建了一个映射 PUT /company { "mappings": { "country": {}, "branch": { "_parent": { "type": "country" } }, "employee": { "_parent": { "type": "branch" } } } } 并添加一些

我正在尝试一个小例子

我创建了一个映射

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冲突。

您“丢失”文档的原因是您给了多个文档相同的
\u id
。在Elasticsearch中,文档id是唯一的,当您使用相同的文档id插入两个文档时,第二次插入将覆盖并更新第一条记录

如果执行
GET/company/branchA/branchA
,您将能够看到文档
的版本大于1


要解决此问题,只需删除
\u id
属性并让Elasticsearch自动生成id,或者为每个文档选择唯一的文档id。

您“丢失”文档的原因是您为多个文档提供了相同的
\u id
。在Elasticsearch中,文档id是唯一的,当您使用相同的文档id插入两个文档时,第二次插入将覆盖并更新第一条记录

如果执行
GET/company/branchA/branchA
,您将能够看到文档
的版本大于1


要解决这个问题,只需删除
\u id
属性,让Elasticsearch自动生成id,或者为每个文档选择唯一的文档id。

在这种情况下,Elasticsearch会丢失具有相同
\u id
和相同
\u父项的记录(记录由
\u id
+
\u父项
标识).

如果没有
\u父项
(分支),则仅使用
\u id
字段来标识记录

在这种情况下,Elasticsearch将丢失具有相同
\u id
和相同
\u父项的记录(记录由
\u id
+
\u父项
标识)。

如果没有
\u父项
(分支),则仅使用
\u id
字段来标识记录

为什么??我添加了3个id的副本。但是,失去1和存在2。为什么不呢?我添加了3个id的副本。但是,失去1和存在2。为什么不呢。