自动生成文档ID时在弹性搜索中更新文档
Updating a document in elastic search when the document id is automatically generated
我有以下脚本,用于将 json 文档插入我的弹性搜索数据库。
for file in /home/ec2-user/Workspace/met_parts/*
do curl -XPOST "http://localhost:9200/ABCD/met/" -d @$file
done
我的 met_parts
文件夹中有一个 'n' 文件列表,每个文件都包含 JSON 记录,如下所示。
{
"Application": "xxxxxxxx",
"FirstTime": 1425502958958,
"LastHost": "127.0.0.1",
"Transactions": "88654"
}
我的 met_parts
文件夹每 hour.So 更新一次 我需要 运行 上面的脚本每 hour.When 一次 我会 curl -XPOST
第二次,我希望更新现有文档,而不是插入新对象。我如何实现这一目标?由于我使用的是 XPOST
,因此 document id
是由弹性搜索自动生成的。
没有 id
就无法更新文档。您应该使用 id
创建文档,以便您知道以后要更新哪个文档。您可以使用以下命令为具有给定 ID 的文档编制索引。
POST <index name>/<type name>/<document id>
{
...
}
请注意,您也可以使用字符串作为文档 ID。
我有以下脚本,用于将 json 文档插入我的弹性搜索数据库。
for file in /home/ec2-user/Workspace/met_parts/*
do curl -XPOST "http://localhost:9200/ABCD/met/" -d @$file
done
我的 met_parts
文件夹中有一个 'n' 文件列表,每个文件都包含 JSON 记录,如下所示。
{
"Application": "xxxxxxxx",
"FirstTime": 1425502958958,
"LastHost": "127.0.0.1",
"Transactions": "88654"
}
我的 met_parts
文件夹每 hour.So 更新一次 我需要 运行 上面的脚本每 hour.When 一次 我会 curl -XPOST
第二次,我希望更新现有文档,而不是插入新对象。我如何实现这一目标?由于我使用的是 XPOST
,因此 document id
是由弹性搜索自动生成的。
没有 id
就无法更新文档。您应该使用 id
创建文档,以便您知道以后要更新哪个文档。您可以使用以下命令为具有给定 ID 的文档编制索引。
POST <index name>/<type name>/<document id>
{
...
}
请注意,您也可以使用字符串作为文档 ID。