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