Skip to content

get/mget fails with json_generation_exception error when using source field that doesn't exist #82891

@jportner

Description

@jportner

Elasticsearch version (bin/elasticsearch --version): main branch (HEAD: 4560a0c)

Plugins installed: []

JVM version (java -version): bundled with Elasticsearch

OS version (uname -a if on a Unix-like system): tested on Ubuntu (x86_64) and Darwin (arm64)

Description of the problem including expected versus actual behavior:

When fetching a document and using _source to attempt to retrieve field that is undefined on a document, it can result in a json_generation_exception error. From @romseygeek:

at a guess, that path doesn't exist in the document and we've missed a null check somewhere

Steps to reproduce:

If you are using Kibana and running ES from snapshot, make sure to use the correct/buggy ES snapshot:

export ES_SNAPSHOT_MANIFEST="https://storage.googleapis.com/kibana-ci-es-snapshots-daily/8.1.0/archives/20220118-151627_25dd4a31/manifest.json"
yarn es snapshot

Create a document:

PUT test/_doc/123
{ "foo": true }

Response (success):

{
  "_index" : "test",
  "_id" : "123",
  "_version" : 1,
  "result" : "created",
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  },
  "_seq_no" : 0,
  "_primary_term" : 1
}

Try to get the document, using a source field that doesn't exist:

GET test/_doc/123?_source=bar

Response (error):

{
  "error" : {
    "root_cause" : [
      {
        "type" : "exception",
        "reason" : "Failed to get id [123] with includes/excludes set"
      }
    ],
    "type" : "exception",
    "reason" : "Failed to get id [123] with includes/excludes set",
    "caused_by" : {
      "type" : "json_generation_exception",
      "reason" : "No current event to copy"
    }
  },
  "status" : 500
}

Try to search for the document, using a source field that doesn't exist:

GET test/_search
{ "_source": ["bar"] }

Response (success):

{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "test",
        "_id" : "123",
        "_score" : 1.0,
        "_source" : { }
      }
    ]
  }
}

It appears this bug was introduced in #81970.

CC @nik9000 @romseygeek

Metadata

Metadata

Assignees

No one assigned

    Labels

    :Search Foundations/MappingIndex mappings, including merging and defining field types>bugTeam:Search FoundationsMeta label for the Search Foundations team in Elasticsearch

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions