elastic / elasticsearch

Free and Open Source, Distributed, RESTful Search Engine
https://www.elastic.co/products/elasticsearch
Other
69.56k stars 24.62k forks source link

`_source: false` should not be possible with update_by_query #84255

Open jpcarey opened 2 years ago

jpcarey commented 2 years ago

Elasticsearch Version

8.0.0

Installed Plugins

No response

Java Version

bundled

OS Version

Elastic Cloud

Problem Description

If _source: false is specified in the request body for an update_by_query, ctx._source will be null. This results in the underlying document data being wiped.

Steps to Reproduce

// POST _bulk
{ "index" : { "_index" : "test" } }
{ "field1" : "some data", "doc": 1 }
{ "index" : { "_index" : "test" } }
{ "field1" : "some data2", "doc": 2 }
{ "index" : { "_index" : "test" } }
{ "field1" : "some data3", "doc": 3 }

// POST test/_update_by_query
{
  "_source": "false",
  "query": {
    "match_all": {}
  },
  "script": {
    "lang": "painless",
    "source": "ctx._source['wiped'] = true;"
  }
}

// GET test/_search
{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 3,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "test",
        "_id" : "YrXQI38BBHHW5cLq9JRF",
        "_score" : 1.0,
        "_source" : {
          "wiped" : true
        }
      },
      {
        "_index" : "test",
        "_id" : "Y7XQI38BBHHW5cLq9JRF",
        "_score" : 1.0,
        "_source" : {
          "wiped" : true
        }
      },
      {
        "_index" : "test",
        "_id" : "ZLXQI38BBHHW5cLq9JRF",
        "_score" : 1.0,
        "_source" : {
          "wiped" : true
        }
      }
    ]
  }
}

Logs (if relevant)

No response

elasticmachine commented 2 years ago

Pinging @elastic/es-data-management (Team:Data Management)