Fail processor
출처: 문서
본문
Fail processor
fail 프로세서는 인덱싱 과정에서 데이터 변환 및 보강을 수행하는 데 유용해요. fail 프로세서의 주요 사용 사례는 특정 조건이 충족될 때 인덱싱 작업을 실패시키는 것이에요.
다음은 fail 프로세서의 구문이에요.
"fail": {
"if": "ctx.foo == 'bar'",
"message": "Custom error message"
}
{% include copy.html %}
구성 매개변수
다음 표에는 fail 프로세서의 필수 및 선택 매개변수가 나와 있어요.
| 매개변수 | 필수/선택 | 설명 |
|---|---|---|
message |
필수 | 실패 응답에 포함될 사용자 정의 오류 메시지예요. |
description |
선택 | 프로세서에 대한 간단한 설명이에요. |
if |
선택 | 프로세서 실행 조건이에요. |
ignore_failure |
선택 | 프로세서가 오류가 발생해도 계속 실행할지 여부를 지정해요. true로 설정하면 실패를 무시해요. 기본값은 false예요. |
on_failure |
선택 | 프로세서가 실패할 경우 실행할 프로세서 목록이에요. |
tag |
선택 | 프로세서의 식별 태그예요. 동일한 유형의 프로세서를 구분하기 위해 디버깅에 유용해요. |
프로세서 사용하기
파이프라인에서 프로세서를 사용하려면 다음 단계를 따르세요.
1단계: 파이프라인 생성
다음 쿼리는 fail-log-pipeline이라는 파이프라인을 생성하며, 로그 이벤트에 대해 의도적으로 파이프라인 실행을 실패시키기 위해 fail 프로세서를 사용해요.
PUT _ingest/pipeline/fail-log-pipeline
{
"description": "A pipeline to test the fail processor for log events",
"processors": [
{
"fail": {
"if": "ctx.user_info.contains('password') || ctx.user_info.contains('credit card')",
"message": "Document containing personally identifiable information (PII) cannot be indexed!"
}
}
]
}
{% include copy-curl.html %}
2단계(선택 사항): 파이프라인 테스트
문서를 인제스트하기 전에 파이프라인을 테스트하는 것이 좋아요. {: .tip}
파이프라인을 테스트하려면 다음 쿼리를 실행하세요.
POST _ingest/pipeline/fail-log-pipeline/_simulate
{
"docs": [
{
"_source": {
"user_info": "Sensitive information including credit card"
}
}
]
}
{% include copy-curl.html %}
응답
다음 예제 응답은 파이프라인이 예상대로 작동하고 있음을 확인해요.
{
"docs": [
{
"error": {
"root_cause": [
{
"type": "fail_processor_exception",
"reason": "Document containing personally identifiable information (PII) cannot be indexed!"
}
],
"type": "fail_processor_exception",
"reason": "Document containing personally identifiable information (PII) cannot be indexed!"
}
}
]
}
{% include copy-curl.html %}
3단계: 문서 인제스트
다음 쿼리는 testindex1이라는 인덱스에 문서를 인제스트해요.
PUT testindex1/_doc/1?pipeline=fail-log-pipeline
{
"user_info": "Sensitive information including credit card"
}
{% include copy-curl.html %}
응답
요청은 user_info에 문자열 credit card가 존재하기 때문에 testindex1 인덱스에 로그 이벤트를 인덱싱하지 못해요. 다음 응답에는 fail 프로세서에 지정된 사용자 정의 오류 메시지가 포함되어 있어요.
"error": {
"root_cause": [
{
"type": "fail_processor_exception",
"reason": "Document containing personally identifiable information (PII) cannot be indexed!"
}
],
"type": "fail_processor_exception",
"reason": "Document containing personally identifiable information (PII) cannot be indexed!"
},
"status": 500
}
{% include copy-curl.html %}
4단계(선택 사항): 문서 검색
파이프라인 실패로 인해 로그 이벤트가 인덱싱되지 않았기 때문에 검색을 시도하면 문서를 찾을 수 없음 오류 "found": false가 발생해요.
GET testindex1/_doc/1
{% include copy-curl.html %}
문서 오류 예제
{
"_index": "testindex1",
"_id": "1",
"found": false
}