0

I need to update my mapping in elastic here is example: current mapping

{
filed1: 6,
filed2: "some string"
}

I need update it to this

{
outer: {
    filed1: 6,
    filed2: "some string"
  }
}

I do it with update_by_query api and this request

{
"script": {
        "source": "ctx._source.outer.field1 = ctx._source.field1; ctx._source.outer.field2 = ctx._source.field2;",
        "lang": "painless"
    },
}

but I got null pointer exception because there is no outer in documents yet

"type": "script_exception",
        "reason": "compile error",
        "script_stack": [
            "... ctx._source.outer.fiel ...",
            "                     ^---- HERE"
        ],

How could I change request?

1 Answer 1

2

You need to do it this way:

    "source": "ctx._source.outer = ['field1': ctx._source.remove('field1'), 'field2': ctx._source.remove('field2')];",
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.