ELK 학습 궤적(3) - Elasticsearch의 간단한 사용(위)

13445 단어
Elasticsearch를 구축한 후에 지금부터 점차적으로 Elasticsearch의 사용 방법을 탐색하기 시작했습니다. 여기서 저는 간단한 명령을 기록하고 다음 편은 이를 더욱 깊이 있게 탐색할 것입니다.

Elasticsearch의 간단한 명령

  • elasticsearch의 건강 상태를 확인하세요
  • curl -GET 127.0.0.1:9200/_cat/health?v  # v , 
    
    epoch      timestamp cluster       status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
    1555329542 11:59:02  elasticsearch yellow          1         1     10  10    0    0        1             0                  -                 90.9%
    
  • 엘라스틱 검색 집단의 건강 상태를 확인하세요
  • curl -GET 127.0.0.1:9200/_cluster/health?pretty   # pretty json , 
    
    {
      "cluster_name" : "elasticsearch",
      "status" : "yellow",
      "timed_out" : false,
      "number_of_nodes" : 1,
      "number_of_data_nodes" : 1,
      "active_primary_shards" : 10,
      "active_shards" : 10,
      "relocating_shards" : 0,
      "initializing_shards" : 0,
      "unassigned_shards" : 1,
      "delayed_unassigned_shards" : 0,
      "number_of_pending_tasks" : 0,
      "number_of_in_flight_fetch" : 0,
      "task_max_waiting_in_queue_millis" : 0,
      "active_shards_percent_as_number" : 90.9090909090909
    }
    
  • 노드 상태 보기
  • curl -GET 127.0.0.1:9200/_cat/nodes?v
    
    ip             heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
    172.19.244.188           45          96   5    0.25    0.11     0.07 mdi       *      izuf6bcs2gy0q80ienjn0yz
    
  • 색인 상태를 확인합니다
  • curl -GET 127.0.0.1:9200/_cat/indices?v
    
    health status index                           uuid                   pri rep docs.count docs.deleted store.size pri.store.size
    green  open   .kibana_task_manager            d52WbBQNRmK9_NB-ScHDYQ   1   0          2            0     46.3kb         46.3kb
    green  open   .monitoring-es-7-2019.04.14     NY_SOwsATN-O-0wQECbB1w   1   0     100855        71917     47.1mb         47.1mb
    green  open   .monitoring-kibana-7-2019.04.14 TrQK23IqQpSYKC_Sz9AAgw   1   0       8638            0      2.6mb          2.6mb
    green  open   kibana_sample_data_flights      9fQjpTomTniy5QPeembbWg   1   0      13059            0      6.5mb          6.5mb
    green  open   .monitoring-kibana-7-2019.04.13 0ZCf0_5sSpmbB1VdqtOaAA   1   0       3370            0        1mb            1mb
    yellow open   test_1                          KsgH0IWVTdO_YIYVTjlVOQ   1   1          6            0     28.1kb         28.1kb
    green  open   .monitoring-es-7-2019.04.15     AN3Gu6DPTKK4fJ-eh0X0lw   1   0      61779        48444     30.6mb         30.6mb
    green  open   .monitoring-kibana-7-2019.04.15 2ec38z9ORxmgB3cNh67rLg   1   0       4397            0      1.5mb          1.5mb
    green  open   .monitoring-es-7-2019.04.13     dGLxQnlVRjapWHqP2esY9g   1   0      30338        16840     14.1mb         14.1mb
    green  open   .kibana_1                       3A228HM4R96hTgv4rZI9bg   1   0         72            5    150.7kb        150.7kb
    
  • 신규 test_2 색인
  • curl -XPUT 127.0.0.1:9200/test_2?pretty
    
    {
      "acknowledged" : true,
      "shards_acknowledged" : true,
      "index" : "test_2"
    }
    
  • 새 레코드 (sample 유형, ID 1)
  • curl -XPUT 127.0.0.1:9200/test_2/sample/1?pretty -H 'Content-Type:application/json' -d '{"name":"xiaoming","age":23}'
    
    {
      "_index" : "test_2",
      "_type" : "sample",
      "_id" : "1",
      "_version" : 1,
      "result" : "created",
      "_shards" : {
        "total" : 2,
        "successful" : 1,
        "failed" : 0
      },
      "_seq_no" : 0,
      "_primary_term" : 1
    }
    
  • 색인 내의 모든 기록을 조회합니다
  •  curl -XGET 127.0.0.1:9200/test_2/sample/_search?pretty
    
    {
      "took" : 0,
      "timed_out" : false,
      "_shards" : {
        "total" : 1,
        "successful" : 1,
        "skipped" : 0,
        "failed" : 0
      },
      "hits" : {
        "total" : {
          "value" : 1,
          "relation" : "eq"
        },
        "max_score" : 1.0,
        "hits" : [
          {
            "_index" : "test_2",
            "_type" : "sample",
            "_id" : "1",
            "_score" : 1.0,
            "_source" : {
              "name" : "xiaoming",
              "age" : 23
            }
          }
        ]
      }
    }
    
  • 조건에 따라 색인 내의 기록을 조회합니다
  •  curl -XGET 127.0.0.1:9200/test_2/sample/_search?pretty&q=name:xiaoming
    
     {
      "took" : 0,
      "timed_out" : false,
      "_shards" : {
        "total" : 1,
        "successful" : 1,
        "skipped" : 0,
        "failed" : 0
      },
      "hits" : {
        "total" : {
          "value" : 1,
          "relation" : "eq"
        },
        "max_score" : 1.0,
        "hits" : [
          {
            "_index" : "test_2",
            "_type" : "sample",
            "_id" : "1",
            "_score" : 1.0,
            "_source" : {
              "name" : "xiaoming",
              "age" : 23
            }
          }
        ]
      }
    }
    
    
  • 기록 덮어쓰기(기록이 없으면 추가)
  • curl -XPOST 127.0.0.1:9200/test_2/sample/1?pretty -H 'Content-Type:application/json' -d '{"name":"xiaohuang","sex":" ","age":24}
    
    {
      "_index" : "test_2",
      "_type" : "sample",
      "_id" : "1",
      "_version" : 7,
      "result" : "updated",
      "_shards" : {
        "total" : 2,
        "successful" : 1,
        "failed" : 0
      },
      "_seq_no" : 17,
      "_primary_term" : 2
    }
    
     curl 127.0.0.1:9200/test_2/_search?pretty
    
    {
      "took" : 0,
      "timed_out" : false,
      "_shards" : {
        "total" : 1,
        "successful" : 1,
        "skipped" : 0,
        "failed" : 0
      },
      "hits" : {
        "total" : {
          "value" : 1,
          "relation" : "eq"
        },
        "max_score" : 1.0,
        "hits" : [
          {
            "_index" : "test_2",
            "_type" : "sample",
            "_id" : "1",
            "_score" : 1.0,
            "_source" : {
              "name" : "xiaohuang",
              "sex" : " ",
              "age" : 24
            }
          }
        ]
      }
    }
    
  • 기록을 갱신하다
  • curl -XPOST 127.0.0.1:9200/test_2/sample/1/_update?pretty -H 'Content-Type:application/json' -d '{"doc":{"name":"xiaohong"}}'
    
    {
      "_index" : "test_2",
      "_type" : "sample",
      "_id" : "1",
      "_version" : 8,
      "result" : "updated",
      "_shards" : {
        "total" : 2,
        "successful" : 1,
        "failed" : 0
      },
      "_seq_no" : 18,
      "_primary_term" : 2
    }
    
    curl 127.0.0.1:9200/test_2/_search?pretty
    
    {
      "took" : 0,
      "timed_out" : false,
      "_shards" : {
        "total" : 1,
        "successful" : 1,
        "skipped" : 0,
        "failed" : 0
      },
      "hits" : {
        "total" : {
          "value" : 1,
          "relation" : "eq"
        },
        "max_score" : 1.0,
        "hits" : [
          {
            "_index" : "test_2",
            "_type" : "sample",
            "_id" : "1",
            "_score" : 1.0,
           "_source" : {
              "name" : "xiaohong",
              "sex" : " ",
              "age" : 24
            }
          }
        ]
      }
    }
    
  • 대량 조작(bulk)
  •  curl -XPOST 127.0.0.1:9200/test_2/sample/_bulk?pretty -H 'Content-Type:application/json' -d '
    {"index":{"_id":"2"}}
    {"name":"xiaohei","age":22}
    {"index":{"_id":"3"}}
    {"name":"xiaohuang","age":23}
    {"update":{"_id":"1"}}
    {"doc":{"name":"xiaoming"}}
    > '
    
    {
      "took" : 29,
      "errors" : false,
      "items" : [
        {
          "index" : {
            "_index" : "test_2",
            "_type" : "sample",
            "_id" : "2",
            "_version" : 1,
            "result" : "created",
            "_shards" : {
              "total" : 2,
              "successful" : 1,
              "failed" : 0
            },
            "_seq_no" : 23,
            "_primary_term" : 2,
            "status" : 201
          }
        },
        {
          "index" : {
            "_index" : "test_2",
            "_type" : "sample",
            "_id" : "3",
            "_version" : 1,
            "result" : "created",
            "_shards" : {
              "total" : 2,
              "successful" : 1,
              "failed" : 0
            },
            "_seq_no" : 24,
            "_primary_term" : 2,
            "status" : 201
          }
        },
        {
          "update" : {
            "_index" : "test_2",
            "_type" : "sample",
            "_id" : "1",
            "_version" : 9,
            "result" : "updated",
            "_shards" : {
              "total" : 2,
              "successful" : 1,
              "failed" : 0
            },
            "_seq_no" : 25,
            "_primary_term" : 2,
            "status" : 200
          }
        }
      ]
    }
    
    curl 127.0.0.1:9200/test_2/_search?pretty
    
    {
      "took" : 2,
      "timed_out" : false,
      "_shards" : {
        "total" : 1,
        "successful" : 1,
        "skipped" : 0,
        "failed" : 0
      },
      "hits" : {
        "total" : {
          "value" : 3,
          "relation" : "eq"
        },
        "max_score" : 1.0,
        "hits" : [
          {
            "_index" : "test_2",
            "_type" : "sample",
            "_id" : "2",
            "_score" : 1.0,
            "_source" : {
              "name" : "xiaohei",
              "age" : 22
            }
          },
          {
            "_index" : "test_2",
            "_type" : "sample",
            "_id" : "3",
            "_score" : 1.0,
            "_source" : {
              "name" : "xiaohuang",
              "age" : 23
            }
          },
          {
            "_index" : "test_2",
            "_type" : "sample",
            "_id" : "1",
            "_score" : 1.0,
            "_source" : {
              "name" : "xiaoming",
              "sex" : " ",
              "age" : 24
            }
          }
        ]
      }
    }
    
  • 기록을 삭제합니다
  • curl -XDELETE 127.0.0.1:9200/test_2/sample/3?pretty
    
    {
      "_index" : "test_2",
      "_type" : "sample",
      "_id" : "3",
      "_version" : 3,
      "result" : "deleted",
      "_shards" : {
        "total" : 2,
        "successful" : 1,
        "failed" : 0
      },
      "_seq_no" : 32,
      "_primary_term" : 2
    }
    
    curl 127.0.0.1:9200/test_2/_search?pretty
    
    {
      "took" : 0,
      "timed_out" : false,
      "_shards" : {
        "total" : 1,
        "successful" : 1,
        "skipped" : 0,
        "failed" : 0
      },
      "hits" : {
        "total" : {
          "value" : 2,
          "relation" : "eq"
        },
        "max_score" : 1.0,
        "hits" : [
          {
            "_index" : "test_2",
            "_type" : "sample",
            "_id" : "2",
            "_score" : 1.0,
            "_source" : {
              "name" : "xiaohei",
              "age" : 22
            }
          },
          {
            "_index" : "test_2",
            "_type" : "sample",
            "_id" : "1",
            "_score" : 1.0,
            "_source" : {
              "name" : "xiaoming",
              "sex" : " ",
              "age" : 24
            }
          }
        ]
      }
    }
    

    먼저 이런 간단한 문장을 기록하고 나중에 천천히 갱신할 것이다.함께 노력하다.

    좋은 웹페이지 즐겨찾기