3

I currently have a deep nested object in one of my mappings:

{
  "doc": {
    "properties": {
      "biography": {
        "properties": {
          "en": {
            "properties": {
              "event": {
                "type": "nested",
                "properties": {
                  "id": {
                    "type": "long"
                  },
...

And documents indexed generally won't have all that structure initialized when I later on want to add a new event. So at the moment, I have a scripted update like this:

if (ctx._source.biography == null)
  ctx._source.biography = new HashMap();
if (ctx._source.biography.${language} == null)
  ctx._source.biography.${language} = new HashMap();
if (ctx._source.biography.${language}.event == null) {
  ctx._source.biography.${language}.event = [ params.event ]
} else {
  ctx._source.biography.${language}.event += [ params.event ]
}

Is there a way to simplify those initializing steps?

villasv
  • 6,304
  • 2
  • 44
  • 78

0 Answers0