LoginSignup
0
0

More than 5 years have passed since last update.

Elasticsearch の Sense を使った自前チュートリアル

Last updated at Posted at 2016-04-08

Sense を使ったチュートリアル

公式の Getting Started ではこのページのように というボタンが置かれています。

Kibana を起動した状態で を押すと、下図のように Elasticsearch へのリクエストする内容がすでに書かれた状態で Sense が立ち上がります。

Kibana のプラグインとして Sense をインストールしておく必要はあります)

チュートリアルボタンのリンク

リンクを見てみると
http://localhost:5601/app/sense/?load_from=https://www.elastic.co/guide/en/elasticsearch/guide/current/snippets/010_Intro/25_Index.json
のように load_from パラメーターに読み込みたいファイルのURLを指定しているだけです。

なので以下のようなファイルをパブリックリポジトリに用意しました。

//github.com/sosuke-k/custom_elasticsearch_ranking/blob/master/00_Check.json
# List all indecies
GET _aliases

raw ファイルを読み込むリンクを load_from に指定したのものが以下です。

下図のようになるはずです。

利用ケースは?

  • 初学者用のチュートリアル
  • 公開してもいいクエリ

Elasticsearch のちょっとした機能や仕様を理解するためだけのチュートリアルにしか向いていませんが、 Elasticsearch を触り始めた自分にとっては後で振り返るのに非常にいいので、残していきたいと思います。

余談

Sense の仕様

以下のようなコードになっていて

api.github.com もサポートしているようです。

else if (/^https?:\/\//.test(sourceLocation)) {
  var loadFrom = {url: sourceLocation, dataType: "text", kbnXsrfToken: false};
  if (/https?:\/\/api.github.com/.test(sourceLocation)) {
    loadFrom.headers = {Accept: "application/vnd.github.v3.raw"};
  }
  $.ajax(loadFrom).done(function (data) {
    resetToValues(defaultServerUrl, data);
    input.moveToNextRequestEdge(true);
    input.highlightCurrentRequestsAndUpdateActionBar();
    input.updateActionsBar();
  });
}

GitHub API とは

GitHub Content API を 使ってみます。

$ curl "https://api.github.com/repos/sosuke-k/custom_elasticsearch_ranking/contents/00_Check.json" | jq '.content' -r | base64 -d
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1054  100  1054    0     0    884      0  0:00:01  0:00:01 --:--:--   884
# List all indecies
GET _aliases

GitHub Content API ではいろんなファイルの情報が json で返ってきて、 content キーに base64 でエンコードされたファイルの中身が入っています。

Sense + GitHub API

こちらもちゃんとロードしてくれました。

0
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
0
0