elasticsearch使用painless語法實現時間戮轉時間字符串

今天要實現一個生日提醒功能,但原來生日存的是時間戮,如:1282014454,對應日期爲:2010-08-17 11:07:34, 單獨判斷生日的時候並不好判斷,現在需要在寫入時間戮的同時把生日部分0817存入另一個字段,可以通過es提供的pipeline中的script處理器來實現,這個script使用painless語言語法,類似java,具體可參考:https://github.com/elastic/elasticsearch/tree/master/modules/lang-painless

{
	"description": "當cno爲空或unionid爲空時移除",
	"version":1,
	"processors": [
		{
			"remove": {
				"if": "ctx.cno == ''",
				"field": "cno"
			}
		},
		{
			"remove": {
				"if": "ctx.unionid == ''",
				"field": "unionid"
			}
		},
		{
			"script": {
				"if": "ctx.member_birthday > 0",
				"lang": "painless",
				"source": "def t = LocalDateTime.ofEpochSecond(ctx.member_birthday, 0, ZoneOffset.ofHours(8));  ctx.birthday = t.format( DateTimeFormatter.ofPattern(\"MMdd\"));"
			}
		}
	]
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章