본문 바로가기
Infra/ElasticSearch

elasticsearch 기본 명령어.

by 골든크랩 2025. 6. 26.
728x90
반응형

 

kibana에서 실행함

 

kibana 명령 콘솔 들어가는 절차

Management -> Dev tools

MySQL           ElasticSearch
================================
테이블              인덱스
컬럼                필드
레코드, 로두         도큐먼트
스키마              맵핑

 

 

실습 명령어

=======================

put my-index

get _cat/indices

put my-other-index
{
    "settings": {
        "index": {
            "number_of_shards": 3,
            "number_of_replicas": 1
        }
    }
}

put my-index/_doc/1
{
  "year": 2025,
  "city": "Seoul",
  "country":"Korea",
  "population_M":4.93
}

put my-index/_doc/2
{
  "year":2021,
  "city":"Sydney",
  "country": "Ausralil",
  "popultin_m" : 5.23
}

# 전체 인덱스 목록 보기
GET /_cat/indices?v

# 클러스터 상태 확인
GET /_cluster/health

# elasticsearch 시스템 정보
get /

# 인덱스 생성 : put 명령으로. 맥 command+enter
put /users

# 인덱스 조회 : get
get /users

get /abc

#생성
put /boards

#조회
get /boards

# 삭제
DELETE /boards

get /users

# 맵핑 생성
put /users/_mappings
{
  "properties": {
    "name": {"type": "keyword"},
    "age" : {"type":"integer"},
    "is_active": {"type": "boolean"}
  }
}

#document 삽입(데이터 삽입) -> _id가 랜덤값으로 들어감
post  /users/_doc
{
  "name":"Alice",
  "age": 28,
  "is_active": false
}

post  /users/_doc
{
  "name":"Dennis",
  "age": 52,
  "is_active": true
}

# 검색
get /users/_search


# 특정 ID 값을 직접 지정하여 저장하는 방법. ID 중복 저장시 에러남
post /users/_create/1
{
  "name":"Jenny",
  "age": 33,
  "is_active": true
}

# UPSERT 기능처럼 동작하게 하는 방법. 없으면 insert, 있으면 update 함.
put /users/_doc/2
{
  "name":"Jason",
  "age": 44,
  "is_active": true
}

#---> 업데이트가 됨
put /users/_doc/2
{
  "name":"Jason2-update-check",
  "age": 44,
  "is_active": true
}

# 특정 id 값 조회하기
get /users/_doc/2

# 특정 id 의 필드를 업데이트 하는 방법 -->> 통채로 업데이트 하는법
put  /users/_doc/1
{
  "name":"Wholy update"  
}

# 일부 필드만 업데이트 하는 바업
post /users/_update/2
{
  "doc": {
    "age" : 18,
    "is_active" : false
  }
}

get /users/_doc/2

# 특정 document 삭제하기
delete /users/_doc/2

 

 

 

 

 

 

728x90
반응형

댓글