Elasticsearch 기본 명령어 정리

Keunjae Song·2020년 9월 4일
0

elasticsearch

목록 보기
1/1

활성 상태 알아내기

curl -XGET 'http://localhost:9200/_cluster/health'
  • pretty print
curl -XGET 'http://localhost:9200/_cluster/health?pretty'
  • 결과
{
  "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" : 10,
  "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" : 50.0
}

index 매핑 정보 확인

필자는 ebooks라는 인덱스를 미리 만들어 두었고, doc이란 type(table)이 있는 상태

curl -XGET 'http://localhost:9200/ebooks?pretty'
  • 결과
    현재 author, body, book_id, cover_img_src, id, title이란 컬럼들이 존재함.
{
  "ebooks" : {
    "aliases" : { },
    "mappings" : {
      "doc" : {
        "properties" : {
          "author" : {
            "type" : "text"
          },
          "body" : {
            "type" : "text"
          },
          "book_id" : {
            "type" : "integer"
          },
          "cover_img_src" : {
            "type" : "text"
          },
          "id" : {
            "type" : "integer"
          },
          "title" : {
            "type" : "text"
          }
        }
      }
    },
    "settings" : {
      "index" : {
        "creation_date" : "1599211840618",
        "number_of_shards" : "5",
        "number_of_replicas" : "1",
        "uuid" : "RjSuEABHTgaKRt-ah8fuUA",
        "version" : {
          "created" : "6070199"
        },
        "provided_name" : "ebooks"
      }
    }
  }
}

json 파일 POST

curl -XPOST http://localhost:9200/ebooks/doc/1 -d @/Users/kjsong/test.json -H 'Content-Type: application/json'

1번 id에 test.json의 내용을 post

  • 결과
{
  "_index" : "ebooks",
  "_type" : "doc",
  "_id" : "1",
  "_version" : 4,
  "result" : "updated",
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  },
  "_seq_no" : 1,
  "_primary_term" : 1
}

특정 type에 들어가있는 document 개수 구하기

curl -XGET 'http://localhost:9200/ebooks/doc/_count?pretty'
  • 결과
{
  "count" : 2,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  }
}

document 삭제

1번 id document 삭제

curl -XDELETE http://localhost:9200/ebooks/doc/1

0개의 댓글