Kibana: インデックスパターン作成API

作成日 2015年04月29日  ·  21コメント  ·  ソース: elastic/kibana

自動化ツールまたはスクリプトで使用される最初の「インデックスパターンの構成」ページを構成するためのAPIがあれば便利です。

enhancement v5.0.0

最も参考になるコメント

curlとjqを使用するkibana6.0の場合:

url="http://localhost:5601"
index_pattern="logstash-*"
time_field="@timestamp"
# Create index pattern and get the created id
# curl -f to fail on error
id=$(curl -f -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
  "$url/api/saved_objects/index-pattern" \
  -d"{\"attributes\":{\"title\":\"$index_pattern\",\"timeFieldName\":\"$time_field\"}}" \
  | jq -r '.id')
# Create the default index
curl -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
  "$url/api/kibana/settings/defaultIndex" \
  -d"{\"value\":\"$id\"}"

全てのコメント21件

同意しました、これがあればいいのですが。 大規模なマッピングの処理を改善するために、マッピング解析をサーバー側に移動することも素晴らしいでしょう。

私はこれを3番目にします。 私は過去2時間、これを行うためにcURLリクエストを強打してきましたが、何もありません。 私は挑戦し続けます...しかし、他の言語からプログラムで実行する最初のインデックスパターン作成方法は非常に有益です。

ええ、私もこれに直面しました。私の解決策(回避策)はあなたの解決策と似ています。私は.kibanaインデックスに直接書き込んでいます。基本的に、Ansibleでは、デプロイ後のタスクで次のようなことを行うことになります。

curl -XPUT http://<es node>:9200/.kibana/index-pattern/events-* -d '{"title" : "events-*",  "timeFieldName": "EventTime"}'
curl -XPUT http://<es node>:9200/.kibana/config/4.1.1 -d '{"defaultIndex" : "events-*"}'

そのインデックスに書き込みたくはありませんが、Kibana HTTPフローも使用したくありませんでした...したがって、よりサポートされた方法でこれを行うことに興味があります。

これが何らかの方法で自動化されていれば素晴らしいと思います。現時点ではElasticdumpを使用してこれを実現しています。これはかなり良いソリューションですが、最初に「手動で」インデックスを作成し、エクスポートしてから追加する必要があります。私たちの人形のコードに。

#5199を支持して閉会

これは5199を支持して閉鎖されましたが、5199は削除されました-これを取り戻す可能性はありますか?

Kibana5のWebページはPOST ing to

  • http:// localhost :5601 / es_admin / .kibana / index-pattern / filebeat- * / _ create 'インデックスを作成します
  • http:// localhost :5601 / api / kibana / settings / defaultIndexでデフォルトを設定
    ただし、kbn-xsrfヘッダーが必要です。

このPOSTでES5にインデックスを追加することができました

curl -XPOST -H 'Content-Type: application/json' \
  'http://localhost:9200/.kibana/index-pattern/filebeat-*' \
  -d'{"title":"filebeat-*","timeFieldName":"@timestamp","notExpandable":true}'

しかし、defaultIndexがどこに保存されているのかわかりません。

POST ing to http:// localhost :9200 / .kibana / config /動作しなくなりました。 ( 4.xで動作しました)。

kbn-xsrfヘッダーは何にでも設定できますが、チェックされていないようです。

curl ${KIBANASERVER}/api/kibana/settings/defaultIndex \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/plain, */*" \
-H "kbn-xsrf: anything" -H "Connection: keep-alive" \
--data-binary ${YOURDEFAULTINDEX} -w "\n" --compressed 

うーん、5.xでこれに対してGETを実行することを望んでいました。

$ curl http://localhost:9200/api/kibana/settings/defaultIndex
No handler found for uri [/api/kibana/settings/defaultIndex] and method [GET]
$ curl http://localhost:9200/.kibana/config/
{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"No endpoint or operation is available at [config]"}],"type":"illegal_argument_exception","reason":"No endpoint or operation is available at [config]"},"status":400}

Kibanaではなくelastic(ポート9200)で最初のGETを起動したようです。

curlとjqを使用するkibana6.0の場合:

url="http://localhost:5601"
index_pattern="logstash-*"
time_field="@timestamp"
# Create index pattern and get the created id
# curl -f to fail on error
id=$(curl -f -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
  "$url/api/saved_objects/index-pattern" \
  -d"{\"attributes\":{\"title\":\"$index_pattern\",\"timeFieldName\":\"$time_field\"}}" \
  | jq -r '.id')
# Create the default index
curl -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
  "$url/api/kibana/settings/defaultIndex" \
  -d"{\"value\":\"$id\"}"

ありがとう@ hobti01 ! これはKibana5.6.4でも機能するようです

Kibana 5.0(およびおそらく6.0)では、 @ hobti01のスクリプトがid=$(... | jq -r '.id')に格納するようにランダムに生成されるのではなく、特定のIndex pattern IDを設定できることがわかりました。 これは、UIで次のフィールドを設定するのと同じです。

screenshot from 2017-12-05 16-11-25

エクスポートされたダッシュボードなどは常にランダムなIDではなく固定IDを参照するため、特定のIDを設定すると、Kibanaの自動展開に特に便利です。

そのIDを/api/saved_objects/index-pattern/THE_IDPOSTすることで、これを行うことができます。

例えば:

curl -f -XPOST -H 'Content-Type: application/json' -H 'kbn-xsrf: anything' 'http://localhost:5601/api/saved_objects/index-pattern/logstash-*' '-d{"attributes":{"title":"logstash-*","timeFieldName":"@timestamp"}}'

@ hobti01のスクリプトは、固定IDを使用するように調整されています。

#!/usr/bin/env bash
# From https://github.com/elastic/kibana/issues/3709
set -euo pipefail
url="http://localhost:5601"
index_pattern="logstash-*"
id="logstash-*"
time_field="@timestamp"
# Create index pattern
# curl -f to fail on error
curl -f -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
  "$url/api/saved_objects/index-pattern/$id" \
  -d"{\"attributes\":{\"title\":\"$index_pattern\",\"timeFieldName\":\"$time_field\"}}"
# Make it the default index
curl -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
  "$url/api/kibana/settings/defaultIndex" \
  -d"{\"value\":\"$id\"}"

IDがすでに存在する場合、スクリプトはcurl: (22) The requested URL returned error: 409 Conflictおよび終了コード22で失敗します。

@ nh2静的IDを使用すると、jqへのパイプを削除できます-提案に感謝します!

静的IDを使用すると、jqへのパイプを削除できます

おっと、そうです! 編集しました。

IDがすでに存在する場合、スクリプトはcurl: (22) The requested URL returned error: 409 Conflictおよび終了コード22で失敗します。

それが不要で、代わりに上書き動作が必要な場合は、最初のcurl呼び出しに"$url/api/saved_objects/index-pattern/$id?overwrite=true"を使用します。

次に、次のように、実行するたびにversionがカウントアップする応答を取得します。

{"id":"logstash-*","type":"index-pattern","version":2,"attributes":{"title":"logstash-*","timeFieldName":"@timestamp"}}
{"id":"logstash-*","type":"index-pattern","version":3,"attributes":{"title":"logstash-*","timeFieldName":"@timestamp"}}

また、Kibana用のexport.json CLIインポーターツールを作成しました: https ://github.com/nh2/kibana-importer

これと上記のインデックスパターン作成カールと一緒に、手動で何もロードしなくても、完全に宣言的な方法でKibanaをデプロイできるようになりました。

参考までに、es6.2.2に対してこれを試してみると失敗します。

/ # curl http://es-api.kube-system.svc.cluster.local:9200
{
  "name" : "Yw3vJ4X",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "HWh0uIo2Q6uL4LOZXnau5Q",
  "version" : {
    "number" : "6.2.2",
    "build_hash" : "10b1edd",
    "build_date" : "2018-02-16T19:01:30.685723Z",
    "build_snapshot" : false,
    "lucene_version" : "7.2.1",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}
/ # curl -f -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" 'http://es-api.kube-system.svc.cluster
.local:9200/api/saved_objects/index-pattern/logstash-*' -d'{"attributes":{"title":"logstash-*","timeFieldName":"<strong i="6">@time</strong>
stamp"}}'
curl: (22) The requested URL returned error: 400 Bad Request

助言がありますか?

@ matthewadams'.kibana 'エンドポイントを使用せずにelasticsearchに対してリクエストを行っているようです。 kibanaに直接POSTを作成してみてください。

ファイルシステムからダッシュボードとインデックスパターンをロードする方法(Chef、Puppet、Saltなどで使用するため)をご希望の場合は、 https ://github.com/elastic/kibana/issues/2310で保証してください。

@sandstrom 「保証された」とは、問題に賛成することを意味する場合、私はそれを行いました。 :)私だけではないことを知って良かったです。

このページは役に立ちましたか?
0 / 5 - 0 評価