Elasticsearch removing field inside field

Hi,

I would like to remove fields from my ES, which are below format,

{
	"parent": {
		"address": {
			"city": "abc",
			"state": "def"
		}
	}
}

By using "script": "ctx._source.remove("parent.address")", it's not removing address field.
But when I try like, "script": "ctx._source.remove("parent")", complete parent is getting removed.

Could someone please help on removing field inside a field.

Thanks,
Ram Prasad G

ctx._source.parent.remove("address") may be?

I guess it depends of the context of the script though. So a a complete example would help.

Hi David,

ctx._source.parent.remove("address"), this is throwing below error.

{
"error": {
"root_cause": [
{
"type": "remote_transport_exception",
"reason": "[wRQCJZ1][x.x.x.x:9300][indices:data/write/update[s]]"
}
],
"type": "illegal_argument_exception",
"reason": "failed to execute script",
"caused_by": {
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"ctx._source.parent.remove("parent.address")",
" ^---- HERE"
],
"script": "ctx._source.parent.remove("parent.address")",
"lang": "painless",
"caused_by": {
"type": "null_pointer_exception",
"reason": null
}
}
},
"status": 400
}

Meanwhile I left it, as we are not using this.

Thanks,
Ram Prasad G

Could you provide a full recreation script as described in About the Elasticsearch category. It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

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