1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Kibana plugin から Elasticsearch API 以外の呼び出し

Posted at

ElasticsearchのAPI呼び出し

Kibana pluginの中から呼び出す場合

const {callWithRequest} = server.plugins.elasticsearch.getCluster('data');
adminCluster.callWithRequest(req, 'ping');

こんな感じで例が書いてあります。
'ping'以外は、
https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html
に書いてある名前で呼び出せます。

他のAPIの呼び出し

Open Distroを入れているので、コンソールから

GET _opendistro/_security/authinfo

を実行するとログイン中のアカウント情報が取れます。

{
  "user" : "User [name=pdev, roles=[], requestedTenant=__user__]",
  "user_name" : "pdev",
  "user_requested_tenant" : "__user__",
  "remote_address" : "127.0.0.1:41076",
  "backend_roles" : [ ],
  "custom_attribute_names" : [
    "attr.internal.testAttr"
  ],
  "roles" : [
    "DEVROLE",
    "own_index"
  ],
  "tenants" : {
    "global_tenant" : false,
    "pdev" : true,
    "devtenant" : true
  },
  "principal" : null,
  "peer_certificates" : "0",
  "sso_logout_url" : null
}

これをPluginのなかで取得するには、どのFunction ?を使えばいいのか1週間くらい悩みました。
https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/transport_request_examples.html
ここに client.transport.request()というものを使う例がありました。

というこで、以下のように呼び出せばいいようです。
API Referenceのところに書いておいてほしいな。。

const {callWithRequest} = server.plugins.elasticsearch.getCluster('data');
adminCluster.callWithRequest(req, 'transport.request', {
 method: "GET",
 path: "_opendistro/_security/authinfo"
});

Javascriptはまだまだ慣れない。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?