假设我在ElasticSearch索引中有一个tag类型,映射如下:
{
"tag": {
"properties": {
"tag": {"type": "string", "store": "yes"},
"aliases": {"type": "string"}
}
}
}每个条目都是一个标记,以及该标记的别名数组。下面是一个示例项目:
{
"word": "weak",
"aliases": ["anemic", "anaemic", "faint", "flimsy"]
}时不时地,我想添加带有别名的新标签词,并将新别名添加到现有标签词中。
添加带有别名的新标签词很容易,它只是一个新文档。但是,如何以合理的方式向现有的标签词添加新的别名?
我知道我可以只搜索标记词,获取它的文档,搜索别名是否已经存在于别名数组中,如果没有添加,则保存。然而,这听起来并不是一个好的解决方案。
有没有办法进行批量更新?
发布于 2012-04-17 21:16:36
ElasticSearch中的所有更新都是通过查找记录、删除旧版本并添加新版本来完成的。通过使用Update API,您可以在将记录一直移动到客户端的过程中节省一点时间。不过,这仍然需要找到记录。
您可能想要的是Update by query。
发布于 2015-06-08 19:16:31
使用_bulk尝试一下
http://127.0.0.1:9200/myindex/type/_bulk
{
"update": {
"_index": "myindex",
"_type": "type",
"_id": "myid"
}
}{
"doc": {
"field": "new value"
}
}{
"update": {
"_index": "myindex",
"_type": "type",
"_id": "id"
}
}{
"doc": {
"field": "new value"
}
}发布于 2016-01-21 09:50:00
这对我很有效。
input_list.dat:
{ "index" : { "_index": "my_index", "_type": "my_type", "_id": "existing-value" } }
{ "Field_to_update": "New_Value" }
{ "index" : { "_index": "my_index", "_type": "my_type", "_id": "existing_value" } }
{ "Field_to_update": "New_Value" }命令:
curl -k -XPOST 'https://my_host:9200/my_url/_bulk' --data-binary "@input_list.dat"; echohttps://stackoverflow.com/questions/10189019
复制相似问题