본문 바로가기
▶ Back-End/Server

OpenSearch 기초 예제 - Index 생성/삭제

by 오늘도 코딩 2024. 5. 20.
728x90
반응형

OpenSearch 기본적인 사용법

*curl 명령어 사용

*HTTPS(SSL/TLS) 적용 후 진행

*설치 과정 아래 참고

*자세한 설명 생략

 

 

▷ 기초 예제 - Index 생성

 

① All Index 조회

 

[옵션 설명]
-k
→ SSL 인증서 검증 하지 않음
*Windwos에서 curl 사용 시 SSL 인증서 CRL(Certificate Revocation List)을 확인할 수 없음

-u admin:설정한 비밀번호
→ 기본 인증을 위한 사용자 정보

https://localhost:9200/_cat/indices
→ _cat/indices API 로 요청(Index 정보 조회)

?v
→ 응답 정보 열의 헤더를 포함

💡curl -XGET -ku admin:TestUser2@ "https://localhost:9200/_cat/indices?v"

전체 Index

 

② Index 생성(자동)

*Opensearch는 Index 없이 데이터를 추가하면 자동으로 Index 생성

 

[옵션 설명]
https://localhost:9200/test/_doc/1
→ test : Index 명
→ _doc/1 : 문서 타입(RDB의 ROW와 비슷)/id

-H "Content-Type: application/json"
→ JSON 형식의 데이터 전송

-d "{\"field\": \"value\"}"
→ JSON 데이터

💡curl -XPUT -ku admin:TestUser2@ "https://localhost:9200/test/_doc/1" -H "Content-Type: application/json" -d "{\"field\": \"value\"}"
💡curl -XGET -ku admin:TestUser2@ "https://localhost:9200/test?pretty

자동 생성된 Index 설정

 

③ Index 생성(수동)

[인덱스 설정]
{
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 0
  },
  "mappings": {
    "properties": {
      "memo": {
        "type": "text"
      },
      "keywords": {
        "type": "keyword"
      }
    }
  }
}

💡curl -XPUT -ku admin:TestUser2@ "https://localhost:9200/test2" -H "Content-Type: application/json" -d "{\"settings\":{\"number_of_shards\":1,\"number_of_replicas\":0},\"mappings\":{\"properties\":{\"memo\":{\"type\":\"text\"},\"keywords\":{\"type\":\"keyword\"}}}}"

 

④ Index 삭제

 

💡curl -XDELETE -ku admin:TestUser2@ "https://localhost:9200/test"
💡curl -XDELETE -ku admin:TestUser2@ "https://localhost:9200/test2"

 

 

▷ 관련 글

 

OpenSearch 설치 방법

Docker를 이용해 OpenSearch를 간단하게 설치할 수 있다.*Single Node*자세한 설명 생략  ▷ OpenSearch 설치 방법 ① OpenSearch 이미지 다운로드 *2024년 04월 18일 기준 OpenSearch version 2.13.0  💡 docker pull opensea

coding-today.tistory.com

 

OpenSearch 기초 예제 - 데이터 추가(_bulk)

OpenSearch 기본적인 사용법*curl 명령어 사용*HTTPS(SSL/TLS) 적용 후 진행*자세한 설명 생략  ▷ 기초 예제 - 데이터추가(_bulk) ① Index 생성*아래 관련 글 참고💡curl -XPUT -ku admin:TestUser2@ "https://localhost:

coding-today.tistory.com

 

 

728x90
728x90

댓글