es 新增字段并赋予默认值

1.先增加后赋值

PUT item_sku/_mapping
{
  "properties": {
     "shop-bag": {
	"type": "integer"
		}
    }
}

POST item_sku/_update_by_query
{
  "query": {
    "bool": {
      "must_not": [
        {
          "exists": {
            "field": "shop_bag"
          }
        }
      ]
    }
  },
  "script": {
    "source": "ctx._source['shop_bag'] = 0"
  }
}

2.增加时赋值

PUT 索引名/_mapping
{
  "properties": {
    "pushTime": {
          "type": "long"
        }
  }
 }
POST 索引名/_update_by_query
{
  "script": {
    "lang": "painless",
    "source": "if (ctx._source.pushTime== null) {ctx._source.pushTime= 1332466576}"
  }
}
posted @ 2022-04-11 15:35  冰镇李子园  阅读(2252)  评论(2)    收藏  举报