首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >文档丢失异常elasticsearch php

文档丢失异常elasticsearch php
EN

Stack Overflow用户
提问于 2018-08-30 20:27:17
回答 1查看 2.4K关注 0票数 1

我想在elastic search中部分地更新现有文档,为此,我编写了更新查询,该查询部分更新文档,而不是需要更新的整个文档样本数据

代码语言:javascript
复制
    {
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 3.0780919,
    "hits": [
      {
        "_index": "trending",
        "_type": "doc",
        "_id": "bx-1605773",
        "_score": 3.0780919,
        "_routing": "1",
        "_source": {
          "id": "bx-1605773",
          "name": "new",
          "db_id": 1605773,
          "user_id": "u-2",
          "box_user": {
            "id": 2,
            "box_id": 1605773,
            "username": "yahoo",
            "full_name": "Yahoo1",
            "is_private": true
          },
          "status": "M",
          "created_at": "2018-08-30T11:58:10Z",
          "type": {
            "name": "box",
            "parent": "u-2"
          },
          "box_posts": []
        }
      }
    ]
  }
}

在本文档中,我仅更新了box的名称和状态,为此,我在ES中编写了以下查询

代码语言:javascript
复制
$params = [
            'index' => 'trending',
            'type' => 'doc',
            'id' => $this->prepareId($box->id, 'bx'),
            'body' => [
                'doc' => [
                    'name' => $box->name,
                ]
            ]
        ];
        try {
            $response = $this->client->update($params);
        } catch (\Exception $ex) {
            return false;
        }

但是当我运行这个查询时,我收到了以下异常

代码语言:javascript
复制
{"error":{"root_cause":[{"type":"document_missing_exception","reason":"[doc][bx-1605773]: document missing","index_uuid":"h8kvjFk7S0usH3YBO-697A","shard":"0","index":"trending"}],"type":"document_missing_exception","reason":"[doc][bx-1605773]: document missing","index_uuid":"h8kvjFk7S0usH3YBO-697A","shard":"0","index":"trending"},"status":404}

甚至是我在elastic search主网站上找到的这个查询

我不知道我在哪里做错了

EN

回答 1

Stack Overflow用户

发布于 2018-08-30 20:34:30

由于使用"routing": "1"为文档编制了索引,因此缺少routing参数。在更新文档时,还需要指定此信息,否则将找不到文档:

代码语言:javascript
复制
$params = [
        'index' => 'trending',
        'type' => 'doc',
        'id' => $this->prepareId($box->id, 'bx'),
>>>     'routing' => 1,
        'body' => [
            'doc' => [
                'name' => $box->name,
            ]
        ]
    ];
    try {
        $response = $this->client->update($params);
    } catch (\Exception $ex) {
        return false;
    }
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52097075

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档