LoginSignup
5
5

More than 5 years have passed since last update.

Elasticsearch APIチートシート

Last updated at Posted at 2015-02-11

まとめ

まぁ、みんなpluginで見るよね

実際に叩いてみたものを書いていくよ

### スレッドの状態確認
curl 'localhost:9200/_cat/thread_pool?v&h=id,host,bulk.active,bulk.queue,bulk.rejected,suggest.active,suggest.rejected,suggest.completed'

id   host               bulk.active bulk.queue bulk.rejected suggest.active suggest.rejected suggest.completed 
2frY elasticsearch04           0          0          3314              0                0                 0 
X5vP elasticsearch01           0          0          5328              0                0                 0 
TXuR elasticsearch05           0          0          3754              0                0                 0 
n4L8 elasticsearch03           0          0          4362              0                0                 0 

rejectされすぎワロタ
### clusterの状態確認
curl -XGET 'http://localhost:9200/_cluster/health?pretty=true'
{
  "cluster_name" : "prd-kakeru",
  "status" : "yellow",
  "timed_out" : false,
  "number_of_nodes" : 28,
  "number_of_data_nodes" : 28,
  "active_primary_shards" : 28122,
  "active_shards" : 55025,
  "relocating_shards" : 0,
  "initializing_shards" : 9,
  "unassigned_shards" : 1210
}
# elasticsearch の再起動時に便利
## shardの配布を止める
curl -XPUT localhost:9200/_cluster/settings -d '{
                "transient" : {
                    "cluster.routing.allocation.enable" : "none"
                }
        }'
## 再起動とかupgradeとか
### hogehgoe

## shardの配布再開
curl -XPUT localhost:9200/_cluster/settings -d '{
                "transient" : {
                    "cluster.routing.allocation.enable" : "all"
                }
        }'
### index削除
## _all
curl -XDELETE 'http://localhost:9200/*'

### 特定index削除
# 存在確認
curl -v -XHEAD 'http://localhost:9200/kakeru-2015.02.02/'

# 削除
curl -XDELETE 'http://localhost:9200/kakeru-2015.02.02/'

とか途中で書いて、curatorの存在に気付いた

### index
## find/_all
curator show --show-indices --prefix activity
activity-2014.11.30
activity-2014.12.01
activity-2014.12.02

## delete
# delete activity-YYYY.MM.DD older than 60 days
curator delete --older-than 60 --prefix activity-            
2015-02-13 02:21:31,113 INFO      Job starting...                                               
2015-02-13 02:21:31,117 INFO      Deleting indices...                                           
2015-02-13 02:21:31,194 INFO      delete_index operation succeeded on activity-2014.11.30       
2015-02-13 02:21:31,240 INFO      delete_index operation succeeded on activity-2014.12.01       
2015-02-13 02:21:31,297 INFO      delete_index operation succeeded on activity-2014.12.02       
2015-02-13 02:21:31,360 INFO      delete_index operation succeeded on activity-2014.12.03       
2015-02-13 02:21:31,404 INFO      delete_index operation succeeded on activity-2014.12.04       
2015-02-13 02:21:31,478 INFO      delete_index operation succeeded on activity-2014.12.05       
2015-02-13 02:21:31,517 INFO      delete_index operation succeeded on activity-2014.12.06       
2015-02-13 02:21:31,563 INFO      delete_index operation succeeded on activity-2014.12.07       
2015-02-13 02:21:31,621 INFO      delete_index operation succeeded on activity-2014.12.08       
2015-02-13 02:21:31,715 INFO      delete_index operation succeeded on activity-2014.12.09       
2015-02-13 02:21:31,793 INFO      delete_index operation succeeded on activity-2014.12.10       
2015-02-13 02:21:31,841 INFO      delete_index operation succeeded on activity-2014.12.11       
2015-02-13 02:21:31,885 INFO      delete_index operation succeeded on activity-2014.12.12       
2015-02-13 02:21:31,932 INFO      delete_index operation succeeded on activity-2014.12.13       
2015-02-13 02:21:31,969 INFO      delete_index operation succeeded on activity-2014.12.14       
2015-02-13 02:21:31,969 INFO      activity-2014.12.15 is within the threshold period (60 days). 
2015-02-13 02:21:31,969 INFO      activity-2014.12.16 is within the threshold period (60 days). 
2015-02-13 02:21:31,970 INFO      activity-2014.12.17 is within the threshold period (60 days). 
2015-02-13 02:21:31,970 INFO      activity-2014.12.18 is within the threshold period (60 days). 
2015-02-13 02:21:31,970 INFO      activity-2014.12.19 is within the threshold period (60 days). 
2015-02-13 02:21:31,970 INFO      activity-2014.12.20 is within the threshold period (60 days). 
2015-02-13 02:21:31,970 INFO      activity-2014.12.21 is within the threshold period (60 days). 
2015-02-13 02:21:31,970 INFO      activity-2014.12.22 is within the threshold period (60 days). 
2015-02-13 02:21:31,970 INFO      activity-2014.12.23 is within the threshold period (60 days). 
2015-02-13 02:21:31,970 INFO      activity-2014.12.24 is within the threshold period (60 days). 
2015-02-13 02:21:31,970 INFO      activity-2014.12.25 is within the threshold period (60 days). 
2015-02-13 02:21:31,971 INFO      activity-2014.12.26 is within the threshold period (60 days). 
2015-02-13 02:21:31,971 INFO      activity-2015.02.12 is within the threshold period (60 days). 
2015-02-13 02:21:31,971 INFO      Specified indices deleted.                                    
2015-02-13 02:21:31,971 INFO      Done in 0:00:00.870249.                                       

クソ便利だな

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