ElasticSearch 操作命令

1、查看集羣狀態

curl -XGET 'localhost:9200/_cat/health?v'

2、創建索引

curl -XPUT 'localhost:9200/index_name?pretty'

index_name: 索引名

3、查看索引

curl -XGET 'localhost:9200/_cat/indices?v'

4、查看索引settings設置

curl -XGET "localhost:9200/index_name/_settings?pretty"

5、查看mapping結構

curl -XGET "localhost:9200/index_name/_mapping?pretty"

6、插入數據

curl -XPUT 'localhost:9200/index_name/index_type/1?pretty' -d'{"name":"wes"}'

index_type:  索引數據類型

7、刪除索引

curl -XDELETE 'localhost:9200/index_name?pretty'

8、查看模板

curl -XGET  'localhost:9200/_template'

9、刪除模板

curl -XDELETE localhost:9200/_template/no_analyzed

10、添加模板-設置副本

curl -XPUT "http://localhost:9200/_template/t1" -d'{"template" : "*", "settings": {"number_of_replicas": "0"}}'

11、添加模板-設置不分詞

curl -XPUT "http://localhost:9200/_template/no_analyzed" -d '

{

  "template":   "*",

   

  "mappings": {

    "_default_": {

      "dynamic_templates": [

        {

          "strings": {

            "match_mapping_type""string",

            "mapping": {

              "type""keyword"             

            }

          }

        }

      ]

    }

  }

   

}'

參考鏈接:https://www.elastic.co/guide/en/elasticsearch/reference/5.5/default-mapping.html

#5.x版本默認啓用分詞,字段的type:text,不分詞表示爲type:keyword:

12、添加模板-設置別名,例如heart_beat_station_real

curl -XPUT "http://localhost:9200/_template/aliases" -d '

{

  "template":   "heart_beat_station_real*",

   

  "aliases" : {

        "a_heart_beat_station_real" : [

        "add" : { "index" "logs*""alias" "a_heart_beat_station_real" } }

        ]

    }

   

}'

13、添加模板-設置數據寫入時間及索引warm模式

curl -XPUT "http://localhost:9200/_template/t1" -d'{"template" : "video*", "settings": {"index.refresh_interval": "30s","index.routing.allocation.require.box_type": "warm"}}'

14、設置索引一次查詢顯示數量最大值(可以將_all改爲index名)

curl -XPUT 'http://localhost:9200/_all/_settings?preserve_existing=true' -d '{

  "index.max_result_window" "1000000"

}'

15、reindex索引,reindex前先設置新索引的mapping

curl -XPOST 'localhost:9200/_reindex'  -d '

  "source": { 

    "index""my_index_name" 

  }, 

  "dest": { 

    "index""my_index_name_new" 

  

}'

16、創建倉庫

curl -XPUT "http://localhost:9200/_snapshot/bak_name"  -d '

{

    "type""fs",

    "settings": {

        "location""/mnt/esbak",

        "compress"true

    }

}'

bak_name:  倉庫名

17、查看倉庫狀態

curl -XGET 'localhost:9200/_snapshot/bak_name?pretty'

18、刪除倉庫

curl -XDELETE "localhost:9200/_snapshot/bak_name

19、備份索引數據,快照名最好跟索引名保持一致

curl -XPUT "localhost:9200/_snapshot/bak_name/video" -d '

{

    "indices""video_violation_201805,video_police_case_201805,video_treat_case_201805"

}'

20、查看快照名及包含的索引

curl -XGET 'localhost:9200/_snapshot/bak_name/_all'

21、刪除快照

curl -XDELETE  'localhost:9200/_snapshot/bak_name/zhongshi-06-20'


 

1

zhongshi-06-20:  快照名

22、增加每分鐘可執行的腳本次數

curl -XPUT localhost:9200/_cluster/settings -d '

{

    "transient" : {

        "script.max_compilations_per_minute" 150

    }

}'

或者在配置文件中修改:script.max_compilations_per_minute: 150

23、x-pack修改用戶密碼

curl -XPUT -u elastic '192.168.75.14:9200/_xpack/security/user/elastic/_password' -d '{

  "password" "123456"

}'

24、es-head插件http-basic認證登錄

http://localhost:9200/?auth_user=username&auth_password=password

username:  用戶名

password: 用戶密碼

25、創建索引並設置副本爲0,mapping如下

curl  -XPUT "http://localhost:9200/test4/" -d '

 

{  

    "settings": {

    "number_of_replicas""0"  

    },

    "mappings" : {

      "test" : {

        "properties" : {

          "name" : {

            "type" "text",

            "fields" : {

              "keyword" : {

                "type" "keyword",

                "ignore_above" 256

              }

            }

          }

        }

      }

    }

}'

26、查看ES節點node信息(heap內存,sm等),直接在瀏覽器運行,curl運行顯示信息爲默認參數信息

http://10.65.3.5:9200/_cat/nodes?v&h=ip,port,v,disk.used,hc,hp,hm,rc,rp,rm,load_1m,qcm,rcm,gc,sc,sm

詳細參數參考:https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-nodes.html

27、動態設置副本爲0

curl -XPUT 'http://10.65.3.5:9200/device/_settings ' -d '

{

   "index" :{

   "number_of_replicas":0

   }

}'

28、mapping,動態匹配字段後設置類型

curl  -XPUT "http://192.168.75.14:9200/_template/point-shape" -d '

    "template" "heart_beat_recorder*",  

    "mappings" : {

      "_default_" : {

        "dynamic_templates" : [

          {

            "integers" : {

              "match" "*point",

              "mapping" : {

                "type" "geo_point"

              }

            }

          },

          {

            "*" : {

              "match" "*shape",

              "mapping" : {

                "type" "geo_shape"

              }

            }

          }

        ]

      }

    }

}'

創建模板,索引heart_beat_recorder*動態匹配以point或shape結尾的字段,並設置其類型

29、添加別名

curl  -XPOST 'http://192.168.75.14:9200/_aliases' -d '

{

    "actions" : [

        "add" : { "index" "heart_beat_recorder_real_*""alias" "a_heart_beat_recorder_real" } }

    ]

}'

30、添加別名模板

curl  -XPUT "http://192.168.75.14:9200/_template/heart_beat_recorder_real_aliase" -d '

{

  "template":   "heart_beat_recorder_real_*",

   

  "aliases" : {

        "a_heart_beat_recorder_real" : [

        "add" : { "index" "heart_beat_recorder_real_*""alias" "a_heart_beat_recorder_real" } }

        ]

    }

   

}'

31、添加更改時間類型模板(long_or_text處信息相當於備註)

 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章