Skip to content

Instantly share code, notes, and snippets.

@toshihirock
Created April 5, 2015 23:36
Show Gist options
  • Save toshihirock/aee943b8cae74e44ed43 to your computer and use it in GitHub Desktop.
Save toshihirock/aee943b8cae74e44ed43 to your computer and use it in GitHub Desktop.

install

設定

  • デフォルト設定ではクラスタ名が「elasticsearch」となるので、「cluster.name = test_cluster」などのようにクラスタ名称を変更すること
  • ノード名も「node.name: node_1」などの用に指定すること

curlによる操作

インデックス作成

curl -XPOST http://localhost:9200/logstash-2015.04.03

インデックス削除

curl -XDELETE http://localhost:9200/logstash-2015.04.03

マッピング設定

curl -XPUT http://localhost:9200/logstash-2015.04.03 -d '
{
  "mappings": {
    "squid_log" : {
      "properties" : {
        "msg12": {
          "type" : "long"
        }
      }
    }
  }
}'

マッピング確認

curl -XGET http://localhost:9200/logstash-2015.04.03/_mapping

データ登録

curl -XPUT http://localhsot:9200/logstash-2015.04.03/apache_log/1 -d '
{
  "host":"localhost",
  "verb":"GET"
}
'

データ取得(全件)

curl -XGET http://localhost:9200/logstash-2015.04.03/_search -d '
{
  "query": {
    "match_all" : {}
  }
}
'

データ取得(絞込)

curl -XGET http://localhost:9200/logstash-2015.04.03/_search -d '
{
  "query": {
    "query_string" : {
    "query" : "msg12:<100"
   }
 }
}
'

fluent-plugin-elasticsearch

  • yum -y install curl-devel
  • /usr/lib64/fluent/ruby/bin/fluent-gem install fluent-plugin-elasticsearch
  • 上記プラグインはfaradayというHTTPクライアントのライブラリを利用しているが、no_proxy環境変数が使えない。http_proxyの設定をしていると自動で使われるので明示的にexport http_proxy=""などする必要がある
  type elasticsearch
  host localhost
  port 9200
  type_name squid_log
  include_tag_key true
  logstash_format true
  tag_key tag
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment