ElasticSearchの良く使うcurlコマンドまとめ
ElasticSearchの良く使うcurlコマンドをまとめました。良かったら使ってください。
コマンドの詳細な説明は書いていませんが、キーワードで調べればすぐ分かるかと思います。
データ投入系
スキーマの登録
curl -XPOST http://localhost:9200/testindex -d @mapper.json
スキーマの追加
curl -XPUT 'http://localhost:9200/testindex/_mapping/test' -d ' { "properties" : { "huga" : { "type" : "long" }, "hoge" : { "type" : "string" } } }'
スキーマの確認
http://localhost:9200/testindex/_mapping?pretty
データの登録
curl -XPOST http://localhost:9200/_bulk --data-binary @data.json >/dev/null
データ削除系
インデックスごと削除
curl -XDELETE 'http://localhost:9200/testindex'
データだけ削除(DELETE *的な)
curl -XDELETE 'http://localhost:9200/testindex/test/_query' -d '{ "query" : { "match_all" : { } } }'
特定条件データだけ削除
curl -XDELETE 'http://localhost:9200/testindex/test/_query' -d '{ "query" : { "term" : {"hoge" : 1} } }'
インデックスの設定変更系
エイリアスを設定
curl -XPOST 'http://localhost:9200/_aliases' -d ' { "actions" : [ {"add": {"index": "test_index", "alias": "test_alias" }} ] }'
レプリカシャードの数を変更
curl -XPUT http://localhost:9200/testindex/_settings -d ' { "index" : { "number_of_replicas" : 0 } }'
ソフトコミットの頻度を変更
curl -XPUT http://localhost:9200/testindex/_settings -d ' { "index" : { "refresh_interval" : "30s" } }'
Warmerを登録
curl -XPUT localhost:9200/testindex/_warmer/warmer_1 -d '{ "query" : { "match_all" : {} }, "aggs" : { "aggs_1" : { "terms" : { "field" : "field" } } } }'
クラスターの設定変更系
シャードの自動移動設定の変更
curl -XPUT http://localhost:9200/_cluster/settings -d '{ "persistent": {"cluster.routing.allocation.enable": "none"} }' curl -XPUT http://localhost:9200/_cluster/settings -d '{ "persistent": {"cluster.routing.allocation.enable": "all"} }'
マスターノードの決定に必要なノード数を変更
curl -XPUT http://localhost:9200/_cluster/settings -d '{ "persistent": {"discovery.zen.minimum_master_nodes": 4} }'
シャードを手動で移動
curl -XPOST 'localhost:9200/_cluster/reroute' -d '{ "commands" : [ { "move" : { "index" : "test", "shard" : 0, "from_node" : "node1", "to_node" : "node2" } } ] }'
Unassignedになっているシャードを再配置
curl -XPOST 'localhost:9200/_cluster/reroute' -d '{ "commands" : [ { { "allocate" : { "index" : "test", "shard" : 1, "node" : "node3" } } ] }'
以上です。何か間違いありましたら教えてください。