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"
}
}
应该怎么操作呢
2 个回复
tacsklet - 公司有用到es
赞同来自:
先查出来结果,把里面的值清空,将想写入的值填进去,重新写一次,可以达到你说的效果,就是比较繁琐。当然有更好的方法欢迎分享。
lzc
赞同来自: