# Elasticsearch update by query using NEST

**URL:** https://discuss.elastic.co/t/elasticsearch-update-by-query-using-nest/198083
**Category:** Elasticsearch
**Created:** [September 4, 2019, 4:48pm UTC](https://discuss.elastic.co/t/elasticsearch-update-by-query-using-nest/198083 "2019-09-04T16:48:24Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![kartheek91](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@kartheek91](https://discuss.elastic.co/u/kartheek91)
#### Post date: [September 4, 2019, 4:48pm UTC](https://discuss.elastic.co/t/elasticsearch-update-by-query-using-nest/198083/1 "2019-09-04T16:48:24Z")

</div>

Can anyone help how to pass paramter dynamically in update by query using nest c# .

> var test= highLevelClient.UpdateByQuery(u =\> u  
> .Index("test")  
> .Type("doc")  
> .Query(q =\> q  
> .Term("\_id", id)  
> )  
> .Script(("ctx.\_source.name=" + name.ToString() ))  
> .Conflicts(Conflicts.Proceed)  
> .Refresh(true)  
> );

Can anyone help me it is throwing me error

---

<div class="post-metadata">

### Author: ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)
#### Post date: [September 5, 2019, 2:25am UTC](https://discuss.elastic.co/t/elasticsearch-update-by-query-using-nest/198083/2 "2019-09-05T02:25:09Z")

</div>

> [@kartheek91](#):
>
> Can anyone help me it is throwing me error

What error is it throwing? Can you include the `test.DebugInformation`?

It looks like you're want to update a single document, based on the `term` query on `_id`. For this, you can use a [scripted update](https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-update.html#_scripted_updates) with the Update API (looks like you're using NEST 6.x?)

```auto
var id = 1;
var name = "updated_name";

var test = client.Update<object>(id, u => u
	.Index("test")
	.Type("doc")
	.Script(s => s
		.Source("ctx._source.name = params.name")
		.Params(p => p
			.Add("name", name)
		)
	)
	.Refresh(Refresh.True)
);

```

which is the following request

```json
POST /test/doc/1/_update
{
  "script": {
    "params": {
      "name": "updated_name"
    },
    "source": "ctx._source.name = params.name"
  }
}

```

for an Update where you are simply overwriting a field value though, you can supply a partial document to do this. [A partial document](https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-update.html#_updates_with_a_partial_document) can be modelled with an anonymous type

```auto
var id = 1;
var name = "updated_name";

var test = client.Update<object>(id, u => u
	.Index("test")
	.Type("doc")
	.Doc(new 
	{
		name = name	
	})
	.Refresh(Refresh.True)
);

```

---

<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: [October 3, 2019, 2:25am UTC](https://discuss.elastic.co/t/elasticsearch-update-by-query-using-nest/198083/3 "2019-10-03T02:25:22Z")

</div>

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