# How to update more fields with script?

**URL:** https://discuss.elastic.co/t/how-to-update-more-fields-with-script/297100
**Category:** Elasticsearch
**Created:** [February 14, 2022, 6:18am UTC](https://discuss.elastic.co/t/how-to-update-more-fields-with-script/297100 "2022-02-14T06:18:54Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![TottyAndBaty](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tottyandbaty/32/101775_2.png) [@TottyAndBaty](https://discuss.elastic.co/u/TottyAndBaty)
#### Post date: [February 14, 2022, 6:18am UTC](https://discuss.elastic.co/t/how-to-update-more-fields-with-script/297100/1 "2022-02-14T06:18:54Z")

</div>

Sorry~ my english is not good....

here is my mapping .

```auto
{
	"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 ....

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

```

here is my script:

```auto
{
	 
	"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 }"
	}
}

```

---

<div class="post-metadata">

### Author: ![TottyAndBaty](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tottyandbaty/32/101775_2.png) [@TottyAndBaty](https://discuss.elastic.co/u/TottyAndBaty)
#### Post date: [February 14, 2022, 1:17pm UTC](https://discuss.elastic.co/t/how-to-update-more-fields-with-script/297100/2 "2022-02-14T13:17:28Z")

</div>

wow~~

I got it~~

```auto
{
	"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 }"
	}
}

```

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [March 14, 2022, 1:17pm UTC](https://discuss.elastic.co/t/how-to-update-more-fields-with-script/297100/3 "2022-03-14T13:17:48Z")

</div>

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