zoukankan      html  css  js  c++  java
  • 【ES】CURL在windows中对ElasticSearch的一些简单的操作

    上一节说了CURL在windows中的安装方式,现在就简单的记录下CURL在windows中对ElasticSearch的一些简单的操作

    直接上操作命令

    首先我们打开cmd命令行

    输入curl -help 检查curl命令是否正常

    查看集群健康

    curl -X GET http://localhost:9200/_cat/health?v
    C:UsersHerbert>curl -X GET http://localhost:9200/_cat/health?v
    epoch      timestamp cluster        status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
    1548657799 14:43:19  my-application yellow          1         1     15  15    0    0       15             0                  -                 50.0%

    获取节点列表 

    curl -X GET http://localhost:9200/_cat/nodes?v
    C:UsersHerbert>curl -X GET http://localhost:9200/_cat/nodes?v
    ip            heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
    192.168.19.64           28          62   3                          mdi       *      node-1

    列出所有索引

    curl -X GET http://localhost:9200/_cat/indices?v
    C:UsersHerbert>curl -X GET http://localhost:9200/_cat/indices?v
    health status index    uuid                   pri rep docs.count docs.deleted store.size pri.store.size
    yellow open   weather  twtmcG7BSemm_FIAlLgINg   5   1          0            0      1.2kb          1.2kb
    yellow open   customer jv2Yz8nzRQKyuzLgVTmiFQ   5   1          0            0      1.2kb          1.2kb
    yellow open   province 0W20G1QxRj6tddFk8sp6UQ   5   1          2            0      9.4kb          9.4kb

    创建索引

    curl -X PUT http://localhost:9200/user?pretty
    C:UsersHerbert>curl -X PUT http://localhost:9200/user?pretty
    {
     "acknowledged" : true,
     "shards_acknowledged" : true,
     "index" : "user"
    }

    检索索引下的数据

    curl http://localhost:9200/province/_search
    C:UsersHerbert>curl http://localhost:9200/province/_search
    {"took":0,"timed_out":false,"_shards":{"total":5,"successful":5,"skipped":0,"failed":0},"hits":{"total":3,"max_score":1.0,"hits":[{"_index":"province","_type":"city","_id":"2","_score":1.0,"_source":{"id":2,"name":"lopa","description":"herbert1","score":8}},{"_index":"province","_type":"city","_id":"1","_score":1.0,"_source":{"id":1,"name":"lopa","description":"herbert","score":8}},{"_index":"province","_type":"city","_id":"3","_score":1.0,"_source":{"id":3,"name":"lopa","description":"herbert1","score":8}}]}}
    {
     "took": 0,
     "timed_out": false,
     "_shards": {
       "total": 5,
       "successful": 5,
       "skipped": 0,
       "failed": 0
     },
     "hits": {
       "total": 3,
       "max_score": 1.0,
       "hits": [{
         "_index": "province",
         "_type": "city",
         "_id": "2",
         "_score": 1.0,
         "_source": {
           "id": 2,
           "name": "lopa",
           "description": "herbert1",
           "score": 8
         }
       }, {
         "_index": "province",
         "_type": "city",
         "_id": "1",
         "_score": 1.0,
         "_source": {
           "id": 1,
           "name": "lopa",
           "description": "herbert",
           "score": 8
         }
       }, {
         "_index": "province",
         "_type": "city",
         "_id": "3",
         "_score": 1.0,
         "_source": {
           "id": 3,
           "name": "lopa",
           "description": "herbert1",
           "score": 8
         }
       }]
     }
    }

    按类型检索

    curl http://localhost:9200/province/city/_search
    C:UsersHerbert>curl http://localhost:9200/province/city/_search
    {"took":9,"timed_out":false,"_shards":{"total":5,"successful":5,"skipped":0,"failed":0},"hits":{"total":3,"max_score":1.0,"hits":[{"_index":"province","_type":"city","_id":"2","_score":1.0,"_source":{"id":2,"name":"lopa","description":"herbert1","score":8}},{"_index":"province","_type":"city","_id":"1","_score":1.0,"_source":{"id":1,"name":"lopa","description":"herbert","score":8}},{"_index":"province","_type":"city","_id":"3","_score":1.0,"_source":{"id":3,"name":"lopa","description":"herbert1","score":8}}]}}

    按id检索

    curl http://localhost:9200/province/city/1
    C:UsersHerbert>curl http://localhost:9200/province/city/1
    {"_index":"province","_type":"city","_id":"1","_version":2,"found":true,"_source":{"id":1,"name":"lopa","description":"herbert","score":8}}

    查看当前节点的所有 Index

    curl -X GET http://localhost:9200/_cat/indices?v
    C:UsersHerbert>curl -X GET http://localhost:9200/_cat/indices?v
    health status index    uuid                   pri rep docs.count docs.deleted store.size pri.store.size
    yellow open   customer jv2Yz8nzRQKyuzLgVTmiFQ   5   1          0            0      1.2kb          1.2kb
    yellow open   province 0W20G1QxRj6tddFk8sp6UQ   5   1          2            0      9.4kb          9.4kb
    yellow open   weather  twtmcG7BSemm_FIAlLgINg   5   1          0            0      1.2kb          1.2kb
    yellow open   user     grXH-HDOTtCxay0tcWb-gA   5   1          0            0      1.1kb          1.1kb

    列出每个 Index 所包含的 Type

    curl localhost:9200/_mapping?pretty=true
    C:UsersHerbert>curl localhost:9200/_mapping?pretty=true
    {
     "customer" : {
       "mappings" : { }
     },
     "province" : {
       "mappings" : {
         "city" : {
           "properties" : {
             "description" : {
               "type" : "text",
               "fields" : {
                 "keyword" : {
                   "type" : "keyword",
                   "ignore_above" : 256
                 }
               }
             },
             "id" : {
               "type" : "long"
             },
             "name" : {
               "type" : "text",
               "fields" : {
                 "keyword" : {
                   "type" : "keyword",
                   "ignore_above" : 256
                 }
               }
             },
             "score" : {
               "type" : "long"
             }
           }
         }
       }
     },
     "weather" : {
       "mappings" : { }
     },
     "user" : {
       "mappings" : { }
     }
    }

    删除一个名叫user的 Index

    curl -X DELETE localhost:9200/user
    C:UsersHerbert>curl -X DELETE localhost:9200/user
    {"acknowledged":true}

    还有一些命令可以查询官网,这里就是一些简单的操作

    官网地址:

    https://www.elastic.co/

    ES中文社区:

    https://elasticsearch.cn/topic/elasticsearch

  • 相关阅读:
    [leedcode 46] Permutations
    [leedcode 45] Jump Game II
    [leedcode 43] Multiply Strings
    [leedcode 42] Trapping Rain Water
    [leedcode 41] First Missing Positive
    [leedcode 40] Combination Sum II
    全排列
    [leedcode 39] Combination Sum
    [leedcode 38] Count and Say
    调和级数求和(分块)
  • 原文地址:https://www.cnblogs.com/zhaixingzhu/p/12562800.html
Copyright © 2011-2022 走看看