使用 shuf 来打乱一个文件中的行或是选择文件中一个随机的行。

更新object类型的feild如何完全覆盖而不是append

Elasticsearch | 作者 大慈大悲掌 | 发布于2020年04月24日 | 阅读数:1350

mapping如下:
mapping = {
"mappings": {
"_doc": {
"properties": {
"id":{
"type": "keyword"
}
},
"dynamic_templates": [
{
"tag":
{
"match": "tag.*",
"match_mapping_type": "double",
"mapping":
{
"type": "double"
}
}
}
]
}
}
}
数据如下:
{
"_index": "tag_test_v1",
"_type": "_doc",
"_id": "1",
"_version": 2,
"_score": 1,
"_source": {
"tag": {
"31": 1.1111,
"32": 1.1111,
"33": 1.1111,
"34": 1.1111
},
"id": "1"
}
}
我这样更新文档
update_doc = {
"doc" : {
"id": id,
"tag" : {
"35":2.1111,
"36":2.1111
}
}
}
result = es.update(index='tag_test_v1', id=id, doc_type='_doc', body=update_doc)
得到的结果是这样
{
"_index": "tag_test_v1",
"_type": "_doc",
"_id": "1",
"_version": 2,
"_score": 1,
"_source": {
"tag": {
"31": 1.1111,
"32": 1.1111,
"33": 1.1111,
"34": 1.1111,
"35": 2.1111,
"36": 2.1111
},
"id": "1"
}
}
想要得到这样的文档
{
"_index": "tag_test_v1",
"_type": "_doc",
"_id": "1",
"_version": 2,
"_score": 1,
"_source": {
"tag": {
"35": 2.1111,
"36": 2.1111
},
"id": "1"
}
}
应该怎么操作呢
已邀请:

tacsklet - 公司有用到es

赞同来自:

从最终存储的情况来看,这些字段都是不同的,因此因为是不同的字段我觉得这不能称之为es的更新,但是可以重新写入,全量覆盖。
先查出来结果,把里面的值清空,将想写入的值填进去,重新写一次,可以达到你说的效果,就是比较繁琐。当然有更好的方法欢迎分享。

lzc

赞同来自:

抽象?

要回复问题请先登录注册