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}"
  }
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM