# How can I update a certain number of documents

**URL:** <https://discuss.elastic.co/t/how-can-i-update-a-certain-number-of-documents/181205>\
**Category:** Elasticsearch\
**Created:** [May 15, 2019, 1:47pm UTC](https://discuss.elastic.co/t/how-can-i-update-a-certain-number-of-documents/181205 "2019-05-15T13:47:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jpaz93](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpaz93/32/39371_2.png) [@jpaz93](https://discuss.elastic.co/u/jpaz93)\
**Post date:** [May 15, 2019, 1:47pm UTC](https://discuss.elastic.co/t/how-can-i-update-a-certain-number-of-documents/181205/1 "2019-05-15T13:47:12Z")

</div>

Hi,

I need help with the following:

In Sql server I can update like this

> update top (100) table1 set field1 = 1

in elasticsearch how can I do something similar?

---

<div class="post-metadata">

**Author:** ![ywelsch](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ywelsch/32/7751_2.png) [@ywelsch](https://discuss.elastic.co/u/ywelsch)\
**Post date:** [May 21, 2019, 8:13pm UTC](https://discuss.elastic.co/t/how-can-i-update-a-certain-number-of-documents/181205/2 "2019-05-21T20:13:53Z")

</div>

See [update-by-query](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html)

---

<div class="post-metadata">

**Author:** ![jpaz93](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpaz93/32/39371_2.png) [@jpaz93](https://discuss.elastic.co/u/jpaz93)\
**Post date:** [May 21, 2019, 9:30pm UTC](https://discuss.elastic.co/t/how-can-i-update-a-certain-number-of-documents/181205/3 "2019-05-21T21:30:53Z")

</div>

Hi, thanks for answering

I try update\_by\_query using size but all records are updated

```
POST event1/_update_by_query
{
  "size": 50,
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "field1": "True"
          }
        },
        {
          "range": {
            "datetime1": {
              "lte": "2018-12-31 23:59:59"
            }
          }
        }
      ]
    }
  },
  "script": {
    "source": "ctx._source.field2 = 'False'"
  }
}

```

What I really want is for only one part to be updated.  
For example, of the 1000 records that exist, only the first 50 are updated

---

<div class="post-metadata">

**Author:** ![ywelsch](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ywelsch/32/7751_2.png) [@ywelsch](https://discuss.elastic.co/u/ywelsch)\
**Post date:** [May 21, 2019, 9:57pm UTC](https://discuss.elastic.co/t/how-can-i-update-a-certain-number-of-documents/181205/4 "2019-05-21T21:57:43Z")

</div>

Can you change the request so that the size parameter is instead sent as an URL parameter, i.e.:

```auto
POST event1/_update_by_query?size=50
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "field1": "True"
          }
        },
        {
          "range": {
            "datetime1": {
              "lte": "2018-12-31 23:59:59"
            }
          }
        }
      ]
    }
  },
  "script": {
    "source": "ctx._source.field2 = 'False'"
  }
}

```

The `size` as currently specified in your input denotes the scroll size, i.e. the batch size that's internally used to fetch the documents to be updated.

Note that we've recently noticed this confusion as well and are in the [process of changing the parameter names](https://github.com/elastic/elasticsearch/pull/41894) to make the distinction clearer.

---

<div class="post-metadata">

**Author:** ![jpaz93](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpaz93/32/39371_2.png) [@jpaz93](https://discuss.elastic.co/u/jpaz93)\
**Post date:** [May 21, 2019, 10:16pm UTC](https://discuss.elastic.co/t/how-can-i-update-a-certain-number-of-documents/181205/5 "2019-05-21T22:16:28Z")

</div>

Perfect,  
Thank you very much.

---

<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:** [June 18, 2019, 10:16pm UTC](https://discuss.elastic.co/t/how-can-i-update-a-certain-number-of-documents/181205/6 "2019-06-18T22:16:33Z")

</div>

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