How can I update a certain number of documents

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?

See update-by-query

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

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

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 to make the distinction clearer.

Perfect,
Thank you very much.

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