Creating a search pipeline
출처: 문서
본문
검색 파이프라인 생성하기
검색 파이프라인은 클러스터 상태에 저장돼요. 검색 파이프라인을 생성하려면 OpenSearch 클러스터에서 정렬된 프로세서 목록을 구성해야 해요. 파이프라인에 동일한 유형의 프로세서를 여러 개 추가할 수 있어요. 각 프로세서에는 다른 프로세서와 구분하는 tag 식별자가 있어요. 특정 프로세서에 태그를 지정하면 오류 메시지를 디버깅할 때 도움이 될 수 있으며, 특히 동일한 유형의 프로세서를 여러 개 추가하는 경우에 유용해요.
예시 요청
다음 요청은 term 쿼리를 사용하여 공개 메시지만 반환하는 filter_query 요청 프로세서와 message 필드를 notification으로 이름을 바꾸는 응답 프로세서가 포함된 검색 파이프라인을 생성해요.
PUT /_search/pipeline/my_pipeline
{
"request_processors": [
{
"filter_query" : {
"tag" : "tag1",
"description" : "This processor is going to restrict to publicly visible documents",
"query" : {
"term": {
"visibility": "public"
}
}
}
}
],
"response_processors": [
{
"rename_field": {
"field": "message",
"target_field": "notification"
}
}
]
}
{% include copy-curl.html %}
프로세서 실패 무시하기
기본적으로 검색 파이프라인은 프로세서 중 하나가 실패하면 중단돼요. 파이프라인이 실패한 프로세서가 있어도 계속 실행되도록 하려면 파이프라인 생성 시 해당 프로세서의 ignore_failure 매개변수를 true로 설정하면 돼요.
"filter_query" : {
"tag" : "tag1",
"description" : "This processor is going to restrict to publicly visible documents",
"ignore_failure": true,
"query" : {
"term": {
"visibility": "public"
}
}
}
프로세서가 실패하면 OpenSearch는 실패를 기록하고 검색 파이프라인의 나머지 모든 프로세서를 계속 실행해요. 실패 여부를 확인하려면 검색 파이프라인 메트릭을 사용할 수 있어요.
검색 파이프라인 업데이트하기
검색 파이프라인을 동적으로 업데이트하려면 Search Pipeline API를 사용하여 검색 파이프라인을 교체해요.
예시 요청
다음 예시 요청은 filter_query 요청 프로세서와 rename_field 응답 프로세서를 추가하여 my_pipeline을 업서트해요.
PUT /_search/pipeline/my_pipeline
{
"request_processors": [
{
"filter_query": {
"tag": "tag1",
"description": "This processor returns only publicly visible documents",
"query": {
"term": {
"visibility": "public"
}
}
}
}
],
"response_processors": [
{
"rename_field": {
"field": "message",
"target_field": "notification"
}
}
]
}
{% include copy-curl.html %}
검색 파이프라인 버전
파이프라인을 생성할 때 version 매개변수에 버전을 지정할 수 있어요.
PUT _search/pipeline/my_pipeline
{
"version": 1234,
"request_processors": [
{
"script": {
"source": """
if (ctx._source['size'] > 100) {
ctx._source['explain'] = false;
}
"""
}
}
]
}
{% include copy-curl.html %}
이 버전은 이후 모든 get pipeline 요청에 대한 응답에 제공돼요.
GET _search/pipeline/my_pipeline
응답에는 파이프라인 버전이 포함돼요.
Response
{: .text-delta}{
"my_pipeline": {
"version": 1234,
"request_processors": [
{
"script": {
"source": """
if (ctx._source['size'] > 100) {
ctx._source['explain'] = false;
}
"""
}
}
]
}
}