How to update more fields with script?

Sorry~ my english is not good....

here is my mapping .

{
	"orders": {
		"aliases": {},
		"mappings": {
			"properties": {
				"created_at": {
					"type": "date"
				}, 
				"expect_pick_start_time": {
					"type": "long"
				},
				"id": {
					"type": "long"
				},  
				"performance": {
					"type": "long"
				}
			}
		} 
		 
	}
}

I wated to update performance like this ....

update orders set performance=if(expect_pick_start_time>0,expect_pick_start_time-UNIX_TIMESTAMP(created_at),0)

here is my script:

{
	 
	"script": {
		"inline": "if(ctx._source['expect_pick_start_time'] > 0){ ctx._source['performance']= ctx._source['expect_pick_start_time']-ctx._source['created_at'].toInstant().toEpochMilli() } else{ ctx._source['performance']=0 }"
	}
}

wow~~

I got it~~

{
	"query": {
		"term": {
			"status": 7
		}
	},
	"script": {
		"inline": "if(ctx._source['expect_pick_start_time'] > 0){ ctx._source['performance']= ctx._source['expect_pick_start_time']-ZonedDateTime.parse(ctx._source['created_at']).toInstant().getEpochSecond() } else{ ctx._source['performance']=0 }"
	}
}

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.