我想在elastic search中部分地更新现有文档,为此,我编写了更新查询,该查询部分更新文档,而不是需要更新的整个文档样本数据
{
"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中编写了以下查询
$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;
}但是当我运行这个查询时,我收到了以下异常
{"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主网站上找到的这个查询
我不知道我在哪里做错了
发布于 2018-08-30 20:34:30
由于使用"routing": "1"为文档编制了索引,因此缺少routing参数。在更新文档时,还需要指定此信息,否则将找不到文档:
$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;
}https://stackoverflow.com/questions/52097075
复制相似问题