ElasticSearch根据匹配某个条件,局部更新文档
2018-01-03 18:57
351 查看
首先声明版本为ES 6.0。
index中有很多文档,要更新这些文档中符合某个条件的所有documents,可以使用ES的_update_by_query的及脚本方式完成:POST请求:http://localhost:9200/indexName/typeName/_update_by_query
{
"script": {"source":"ctx._source['user_name']='LsiuLi';ctx._source['assignedto_id']='123';"},
"query": {"term": {"user_id": 60}}
}
执行上面的query,意思是把当前index/type下的所有符合user_id为 60的document,把这些document的user_name字段全部修改成LsiuLi,把assignedto_id 改成123。
如果增加数组元素: http://localhost:9200/1909_user/user/15670260/_update {
"script": {
"lang": "painless",
"source":"ctx._source['field_mult_value_7917'].add(params.hobby)",
"params" : {
"hobby" : "c"
}
}
}script 删除index中的field: http://localhost:9200/1542_case/case/_update_by_query?wait_for_completion=false&conflicts=proceed
{
"script": {"source":"ctx._source.remove('user_field_email_5613')"}
}wait_for_completion=false可以直接返回http请求,哪怕index中的field还没删完。
参考链接: https://www.elastic.co/guide/en/elasticsearch/reference/6.0/modules-scripting-using.html https://www.cnblogs.com/rodge-run/p/7760308.html
index中有很多文档,要更新这些文档中符合某个条件的所有documents,可以使用ES的_update_by_query的及脚本方式完成:POST请求:http://localhost:9200/indexName/typeName/_update_by_query
{
"script": {"source":"ctx._source['user_name']='LsiuLi';ctx._source['assignedto_id']='123';"},
"query": {"term": {"user_id": 60}}
}
执行上面的query,意思是把当前index/type下的所有符合user_id为 60的document,把这些document的user_name字段全部修改成LsiuLi,把assignedto_id 改成123。
如果增加数组元素: http://localhost:9200/1909_user/user/15670260/_update {
"script": {
"lang": "painless",
"source":"ctx._source['field_mult_value_7917'].add(params.hobby)",
"params" : {
"hobby" : "c"
}
}
}script 删除index中的field: http://localhost:9200/1542_case/case/_update_by_query?wait_for_completion=false&conflicts=proceed
{
"script": {"source":"ctx._source.remove('user_field_email_5613')"}
}wait_for_completion=false可以直接返回http请求,哪怕index中的field还没删完。
参考链接: https://www.elastic.co/guide/en/elasticsearch/reference/6.0/modules-scripting-using.html https://www.cnblogs.com/rodge-run/p/7760308.html
相关文章推荐
- Elasticsearch之文档局部更新。
- Elasticsearch(文档局部更新)
- SQL两表匹配,将A表的指定字段所有内容根据条件更新B表指定字段的所有内容
- ElasticSearch入门 第四篇:使用C#添加和更新文档
- 根据条件更新字段
- 两表更新:根据条件从一个表里面查询出符合条件的结果更新另一个表
- ElasticSearh更新nested字段(Array数组)。怎么根据查询条件(query)复制一个(index)到新的Index how to update by query a nested fields data for elasticsearch
- Elasticsearch局部更新(数组追加)
- ElasticsearchTemplate的详细使用,完成多条件查询、匹配度查询等
- ElasticSearch入门 第四篇:使用C#添加和更新文档
- 更新 将B表的数据更新到A表中的某个字段的sql(根据条件)
- SQL根据条件批量update更新字段案例
- 【数据库】同一字段根据不同条件更新的sql语句的写法
- SQL-根据多个条件更新数据
- update语句根据条件更新某字段的值
- mongodb中根据内嵌文档中的条件查询
- 根据条件来更新表的所有记录T-Sql
- j2eeSSH利用JSON实现异步查询,根据条件查询出结果,实现结果部分局部刷新保留查询结果
- 更新根据条件查出的语句
- ElasticSearch入门 第四篇:使用C#添加和更新文档