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 생성(자동)
*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 생성(수동)
[인덱스 설정]
{
"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"
▷ 관련 글
728x90
728x90
'▶ Back-End > Server' 카테고리의 다른 글
OpenSearch Dashboard Index Patterns 생성 (0) | 2024.05.20 |
---|---|
OpenSearch 기초 예제 - 데이터 추가(_bulk) (0) | 2024.05.20 |
OpenSearch HTTPS(SSL/TLS) 설정 방법 (0) | 2024.04.30 |
OpenSearch + OpenSearch Dashboard 연동 방법 (0) | 2024.04.22 |
OpenSearch Dashboard 설치 방법 (0) | 2024.04.22 |
댓글