elasticsearch 索引增删改示例

1.索引条件更新   

  update collect_material_page_address set IsCollectUri=true where
    IsCollectUri=false and CollectUri like 'https://www.futureelectronics.cn/search?q=Vishay:relevance:manufacturerName:Vishay%'

POST collect_material_page_address/_update_by_query
{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "IsCollectUri": {
              "value": "false"
            }
          }
        },
        {
          "wildcard": {
            "CollectUri": {
              "value": "https://www.futureelectronics.cn/search?q=Vishay:relevance:manufacturerName:Vishay*"
            }
          }
        }
      ]
    }
  },
   "script": {
      "source": "ctx._source['IsCollectUri']='true'"
    }
}

 2.删除  根据Status为2的批量删除

post sku_goods_resource_down/_delete_by_query
{
  "query":{
    "term": {
      "Status": {
        "value": 2
      }
    }
  }
}

 3.更新Nested类型中的子字段值

POST /sku_goods/_update_by_query
{
  "query": {
    "term": {
      "Id": {
        "value": "08db4631-100b-4821-81b8-d9b7b98ec4bd"
      }
    }
  },
   "script": {
        "source": "for(e in ctx._source.SpecItems){if (e.SpecId== '08db44ac-c85b-412e-8342-198d861bace6') {e.SpecValue = '0.197(5.00mm)';}}",
        "lang": "painless"
    }
}

 

除了标准的参数,如 pretty,通过查询 API 还支持 refresh,wait_for_completion,wait_for_active_shards和 timeout。
比如滚动批删除,默认是1000,改成5000如下:
twitter/_delete_by_query?scroll_size=5000

wait_for_completion=false,那么Elasticsearch将执行一些预检检查、启动请求、然后返回一个任务,可以与Tasks API一起使用来取消或获取任务的状态。
比如:twitter/_delete_by_query?wait_for_completion=false

 

posted on 2022-12-26 12:30  花阴偷移  阅读(8)  评论(0编辑  收藏  举报

导航