ELasticsearch Post bulk on elastic xpack role

443 views Asked by At

I have an Elastic cluster with xpack enable.

I'd like to make a backup of all xpack roles created :

GET _xpack/security/role

=> I get a big JSON, ex :

{
  "kibana_dashboard_only_user": {
    "cluster": [],
    "indices": [
      {
        "names": [
          ".kibana*"
        ],
        "privileges": [
          "read",
          "view_index_metadata"
        ]
      }
    ],
    "run_as": [],
    "metadata": {
      "_reserved": true
    },
    "transient_metadata": {
      "enabled": true
    }
  },
  "watcher_admin": {
    "cluster": [
      "manage_watcher"
    ],
    "indices": [
      {
        "names": [
          ".watches",
          ".triggered_watches",
          ".watcher-history-*"
        ],
        "privileges": [
          "read"
        ]
      }
    ],
    "run_as": [],
    "metadata": {
      "_reserved": true
    },
    "transient_metadata": {
      "enabled": true
    }
  },
  ....
}

And now I'd like to put it back in the cluster (or another). I cannot just PUT it to _xpack/security/role. If i understand correctly I have to use bulk :

$ curl --user elastic:password https://elastic:9200/_xpack/security/_bulk?pretty -XPOST -H 'Content-Type: application/json' -d '
{"index":{"_index": "_xpack/security/role"}}
{"ROOOOLE" : {"cluster" : [ ],"indices" : [{"names" : [".kibana*"],"privileges" : ["read","view_index_metadata"]}],"run_as" : [ ],"metadata" : {"_reserved" : true},"transient_metadata" : {"enabled" : true}}}
'

But I get an error:

{
  "took" : 3,
  "errors" : true,
  "items" : [
    {
      "index" : {
        "_index" : "_xpack/security/role",
        "_type" : "security",
        "_id" : null,
        "status" : 400,
        "error" : {
          "type" : "invalid_index_name_exception",
          "reason" : "Invalid index name [_xpack/security/role], must not contain the following characters [ , \", *, \\, <, |, ,, >, /, ?]",
          "index_uuid" : "_na_",
          "index" : "_xpack/security/role"
        }
      }
    }
  ]
}

Is there a way to do this easily? Or do I have to parse the JSON, and put each role one by one to:

  • _xpack/security/role/rolexxx
  • _xpack/security/role/roleyyy
  • ...

More globally, is there a way to get all data of an index (config index), then upload it back or put it into another cluster?

0

There are 0 answers