org.opensearch.action.search.SearchPhaseExecutionException: all shards failed
은 OpenSearch에서 검색 쿼리를 수행했지만, 모든 샤드가 실패해서 결과를 반환할 수 없었다는 뜻이에요.
💥 주요 원인 정리
원인 | 설명 |
❌ 인덱스 손상 | 일부 샤드가 손상되어 쿼리를 처리할 수 없음 |
🛑 매핑 오류 | 필드 타입 불일치 등으로 쿼리 실행 중 예외 발생 |
🔒 샤드 비정상 | 샤드가 UNASSIGNED 상태일 수 있음 |
🔍 잘못된 쿼리 | 잘못된 필드명이나 DSL 오류 |
⛔ 리소스 문제 | 디스크 부족, 노드 다운, 클러스터 헬스 red 등 |
✅ 해결 절차
1. 클러스터 상태 확인
curl -X GET http://localhost:9200/_cluster/health?pretty
확인할 것:
- "status": "red" → 일부 인덱스 또는 샤드가 완전히 작동 중지
- "unassigned_shards": 값이 0보다 크면 문제 있음
2. 샤드 상태 확인
curl -X GET http://localhost:9200/_cat/shards?v
샤드 상태가 "UNASSIGNED", "INITIALIZING"이라면 문제가 있는 것.
3. 문제 인덱스 확인
curl -X GET http://localhost:9200/_cat/indices?v
여기서 상태(health)가 red로 표시된 인덱스가 문제 인덱스입니다.
4. 에러 상세 보기
OpenSearch 로그 또는 다음 API로 어떤 샤드가 왜 실패했는지 확인:
curl -X GET http://localhost:9200/index-name/_search?pretty
→ 응답 중 "failures" 항목에서 에러 메시지 확인 가능
💡 대응 방안
💊 빠른 임시조치
- 문제 인덱스가 무의미한 경우:
curl -X DELETE http://localhost:9200/problem-index-name
🔁 샤드 재할당 시도
curl -X POST http://localhost:9200/_cluster/reroute?retry_failed=true
🛠️ 유용한 추가 팁
- 디스크 부족 시:
curl -X GET http://localhost:9200/_nodes/stats/fs?pretty
- 매핑 오류 추적:
curl -X GET http://localhost:9200/index-name/_mapping?pretty
📌 예시 시나리오
❓ 쿼리 오류로 all shards failed
{
"error": {
"root_cause": [
{
"type": "query_shard_exception",
"reason": "failed to create query: Field [user_id] of type [keyword] does not support match operations"
}
]
}
}
🧩 해결: match 대신 term 쿼리 사용해야 함 (keyword 타입일 경우)
반응형
'프로그래밍 > 개발일지' 카테고리의 다른 글
C# ODBC 엑셀 연결 문제점 (0) | 2022.09.28 |
---|