Reputation: 73
Hi I am following this https://opendistro.github.io/for-elasticsearch-docs/docs/security/access-control/api/#create-tenant documentation to create tenant at Elasticsearch.
We can also create an index using index API https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html.
Is there any way to crate index-pattern with an index for a specific tenant using any API? (We can do the same manually from Elasticsearch Kibana UI)
Upvotes: 1
Views: 1058
Reputation: 1
Response above won't work with AWS-based Elasticsearch 7.10
# curl -k -v -X PUT -u '...:...' -H 'Content-Type: application/json' -H "kbn-xsrf: reporting" -d '{\"attributes\":{\"title\": \"'\"$index_pattern_name\"'\",\"fields\": \"[{"count":0,"name":"_id","type":"string","scripted":false,"searchable":false,"aggregatable":false,"readFromDocValues":false},{"count":0,"name":"_index","type":"string","scripted":false,"searchable":false,"aggregatable":false,"readFromDocValues":false},{"count":0,"name":"_score","type":"number","scripted":false,"searchable":false,"aggregatable":false,"readFromDocValues":false},{"count":0,"name":"_source","type":"_source","scripted":false,"searchable":false,"aggregatable":false,"readFromDocValues":false},{"count":0,"name":"_type","type":"string","scripted":false,"searchable":false,"aggregatable":false,"readFromDocValues":false}]\"}}' https://.../tenant-global_tenant
{"error":{"root_cause":[{"type":"parse_exception","reason":"Failed to parse content to map"}],"type":"parse_exception","reason":"Failed to parse content to map","caused_by":{"type":"json_parse_exception","reason":"Unexpected character ('\\' (code 92)): was expecting double-quote to start field name\n at [Source: (byte[])\"{\\\"attributes\\\":{\\\"title\\\": \\\"\"\"\\\",\\\"fields\\\": \\\"[{\"count\":0,\"name\":\"_id\",\"type\":\"string\",\"scripted\":false,\"searchable\":false,\"aggregatable\":false,\"readFromDocValues\":false},{\"count\":0,\"name\":\"_index\",\"type\":\"string\",\"scripted\":false,\"searchable\":false,\"aggregatable\":false,\"readFromDocValues\":false},{\"count\":0,\"name\":\"_score\",\"type\":\"number\",\"scripted\":false,\"searchable\":false,\"aggregatable\":false,\"readFromDocValues\":false},{\"count\":0,\"name\":\"_source\",\"type\":\"_source\",\"scripted\":false,\"searchabl\"[truncated 187 bytes]; line: 1, column: 3]"}},"status":400}
Upvotes: 0
Reputation: 637
Yes there is a way to do it.
You should first create a tenant using security plugin. (This should be installed.)
curl -X PUT $OPENDISTRO_HOSTURL/_opendistro/_security/api/tenants/[tenant_name] –d '{"description":"[description of the tenant]"}' –H "Content-Type: application/json" –u [user]:[pass]
And then you can call API
curl -k -v -X POST -u [user]:[pass] -H 'Content-Type: application/json' -H \"kbn-xsrf: reporting\" -d
'{\"attributes\":{\"title\": \"'\"$index_pattern_name\"'\",\"fields\": \"[{\\\"count\\\":0,\\\"name\\\":\\\"_id\\\",\\\"type\\\":\\\"string\\\",\\\"scripted\\\":false,\\\"searchable\\\":false,\\\"aggregatable\\\":false,\\\"readFromDocValues\\\":false},{\\\"count\\\":0,\\\"name\\\":\\\"_index\\\",\\\"type\\\":\\\"string\\\",\\\"scripted\\\":false,\\\"searchable\\\":false,\\\"aggregatable\\\":false,\\\"readFromDocValues\\\":false},{\\\"count\\\":0,\\\"name\\\":\\\"_score\\\",\\\"type\\\":\\\"number\\\",\\\"scripted\\\":false,\\\"searchable\\\":false,\\\"aggregatable\\\":false,\\\"readFromDocValues\\\":false},{\\\"count\\\":0,\\\"name\\\":\\\"_source\\\",\\\"type\\\":\\\"_source\\\",\\\"scripted\\\":false,\\\"searchable\\\":false,\\\"aggregatable\\\":false,\\\"readFromDocValues\\\":false},{\\\"count\\\":0,\\\"name\\\":\\\"_type\\\",\\\"type\\\":\\\"string\\\",\\\"scripted\\\":false,\\\"searchable\\\":false,\\\"aggregatable\\\":false,\\\"readFromDocValues\\\":false}]\"}}'
$KIBANA_HOSTURL/tenant-$TENANT_NAME
Upvotes: 0