当前位置:   article > 正文

ElasticSearch的update_by_query使用_es update by query

es update by query

ElasticSearch的update_by_query语句可以很方便地为原有es表修改字段和新增字段,如下面的例子所示:

1.将资产表中area为空的字段赋值为'无'

  1. POST soc-system/_update_by_query
  2. {
  3. "script": {
  4. "source": "ctx._source['area']='无'"
  5. },
  6. "query": {
  7. "bool": {
  8. "must_not": [
  9. {
  10. "exists": {
  11. "field": "area"
  12. }
  13. }
  14. ]
  15. }
  16. }
  17. }

2.添加一个网段字段,其值根据已有字段ip截取而来

  1. POST soc-system/_update_by_query
  2. {
  3. "script": {
  4. "source": "def a=ctx._source['ip'].lastIndexOf('.');def sec=ctx._source['ip'].substring(0,a);ctx._source['ipSection']=sec+'.0'"
  5. },
  6. "query": {
  7. "bool": {
  8. "must": [
  9. {
  10. "exists": {
  11. "field": "ip"
  12. }
  13. }
  14. ]
  15. }
  16. }
  17. }

其中script的语法为painless,具体语法参考这里

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/734088
推荐阅读
相关标签
  

闽ICP备14008679号