shell脚本变量在 curl 使用

项目背景:

     项目需求,需要每天删除elasticsearch的索引中数据。也就是需要一个定时任务,来完成。

 

解决方式:

         通过shell脚本定时删除指定条件的数据。

 

 

通过curl命令删除elasticsearch索引的数据,命令如下:

curl -XPOST -H "Content-Type: application/json" -H "Authorization: Basic xx" http://11.3.16.229:40000/item_sku/item_sku/_delete_by_query?pretty -d '{
   "query":{
    "bool":{
      "must":[       
                     {"match": {"version": "2019-09-05"}},
                     {"match": {"item_sku_id": "46250906443"}}              
      ]
    }
  }
}'

 通过shell脚本把时间可以替换,脚本定时执行就可以了

delete_data="2019-09-05"
json="{\"query\":{\"bool\":{\"must\":[{\"match\": {\"version\":\"$delete_data\"}},{\"match\": {\"item_sku_id\":\"46250906443\"}}]}}}"
echo $json
curl -XPOST -H "Content-Type: application/json" -H "Authorization: Basic xxx" http://11.3.16.229:40000/item_sku/item_sku/_delete_by_query?pretty -d "$json"

 

你可能感兴趣的:(shell,shell,变量,elasticsearch)