OpenSearch 는 REST API를 중심으로 동작합니다.
이 포스트에서는 동일한 작업을 Dev Tools, curl, Python client에서 어떻게 실행하는지 비교합니다.
OpenSearch는 표준 REST API를 지원하므로, 동일한 로직을 도구에 맞춰 변환하여 사용할 수 있습니다.
아래 비교표를 통해 각 환경에 맞는 문법을 익히고 상황에 적합한 도구를 선택하시면 됩니다.
작업 방식별 특징 #
| 방식 | 용도 | 장점 | 한계 |
|---|---|---|---|
| Dev Tools | 쿼리 실험, 디버깅 | 자동 완성 지원, JSON 구조 가독성 높음 | 앱 코드와 분리됨, 자동화 불가 |
| curl | 상태 확인, 스크립트 | 가볍고 별도 라이브러리 설치 불필요 | 복잡한 로직 및 데이터 처리 불편 |
| Python Client | 쿼리 앱 구현 | 객체 지향적 처리, LLM 연동 용이 | 환경 설정 및 예외 처리 코드 필요 |
주요 작업별 코드 비교 #
클러스터 상태 확인 #
클러스터가 정상적으로 동작하는지 확인하는 가장 기초적인 단계입니다.
- Dev Tools
GET /_cluster/health?pretty - curl
curl -k -u admin:password -X GET "<https://localhost:9200/_cluster/health?pretty>" - Python Client
print(client.cluster.health())
인덱스 생성 #
샤드 수와 레플리카 수를 설정하여 인덱스를 명시적으로 생성합니다.
- Dev Tools
PUT /rag_docs_v1
{
"settings": {
"index": {
"number_of_shards": 1,
"number_of_replicas": 0
}
}
}
- CURL
curl -k -u admin:password -X PUT "<https://localhost:9200/rag_docs_v1>" \\
-H "Content-Type: application/json" \\
-d '{"settings": {"number_of_shards": 1, "number_of_replicas": 0}}'- Python Client
body = {
"settings": {
"index": {
"number_of_shards": 1,
"number_of_replicas": 0
}
}
}
client.indices.create(index="rag_docs_v1", body=body)
문서 색인 #
실제 데이터를 인덱스에 저장합니다.
(Opensearch에서 “인덱스(색인)를 한다”는 문서를 삽입(insert) 한다는 의미입니다.)
- Dev Tools
POST /rag_docs_v1/_doc/1
{
"title": "OpenSearch RAG 가이드",
"content": "이 문서는 RAG 시스템 구축을 위한 가이드입니다.",
"created_at": "2026-05-07"
}
- cURL
curl -k -u admin:password -X POST "<https://localhost:9200/rag_docs_v1/_doc/1>" \\
-H "Content-Type: application/json" \\
-d '{
"title": "OpenSearch RAG 가이드",
"content": "이 문서는 RAG 시스템 구축을 위한 가이드입니다.",
"created_at": "2026-05-07"
}'
- Python Client
doc = {
"title": "OpenSearch RAG 가이드",
"content": "이 문서는 RAG 시스템 구축을 위한 가이드입니다.",
"created_at": "2026-05-07"
}
client.index(index="rag_docs_v1", body=doc, id="1", refresh=True)
문서 검색 #
특정 키워드로 데이터를 조회합니다.
- Dev Tools
GET /rag_docs_v1/_search
{
"query": {
"match": {
"content": "RAG 가이드"
}
}
}
- CURL
curl -k -u admin:password -X GET "<https://localhost:9200/rag_docs_v1/_search>" \\
-H "Content-Type: application/json" \\
-d '{
"query": {
"match": {
"content": "RAG 가이드"
}
}
}'
- Python Client
query = {
"query": {
"match": {"content": "RAG 가이드"}
}
}
response = client.search(index="rag_docs_v1", body=query)
print(response['hits']['hits'])