본문 바로가기
WIKI 기술 지식 베이스

Collapse processor

원문 보기 위키 갱신

출처: 문서

본문

축소 프로세서

Introduced 2.12 {: .label .label-purple }

collapse 응답 프로세서는 결과 집합에서 이전 문서와 특정 필드의 값이 같은 히트를 버려요. 이는 검색 요청에서 collapse 매개변수를 전달하는 것과 비슷하지만, 응답 프로세서는 모든 샤드에서 가져온 후 응답에 적용돼요. collapse 응답 프로세서는 rescore 검색 요청 매개변수와 함께 사용하거나 재순위화 응답 프로세서 후에 적용할 수 있어요.

collapse 응답 프로세서를 사용하면 size보다 적은 결과가 반환될 가능성이 있어요. 히트가 이미 size보다 작거나 같은 집합에서 버려지기 때문이에요. size 히트를 반환할 가능성을 높이려면 oversample 요청 프로세서와 truncate_hits 응답 프로세서를 사용하세요. 이 예제에 나와 있어요.

요청 본문 필드

다음 표는 모든 요청 필드를 나열해요.

필드 데이터 타입 설명
field String 각 반환된 검색 히트에서 값을 읽을 필드예요. 각 필드 값에 대해 첫 번째 히트만 검색 응답에 반환돼요. 필수 항목이에요.
context_prefix String 충돌을 피하기 위해 특정 범위에서 original_size 변수를 읽는 데 사용할 수 있어요. 선택 사항이에요.
tag String 프로세서의 식별자예요. 선택 사항이에요.
description String 프로세서에 대한 설명이에요. 선택 사항이에요.
ignore_failure Boolean true인 경우 OpenSearch가 이 프로세서의 실패를 무시하고 검색 파이프라인에서 나머지 프로세서를 계속 실행해요. 선택 사항이에요. 기본값은 false예요.

예제

다음 예제는 collapse 프로세서와 함께 검색 파이프라인을 사용하는 방법을 보여줘요.

설정

축소에 사용할 필드가 포함된 여러 문서를 생성해요:

POST /_bulk
{ "create":{"_index":"my_index","_id":1}}
{ "title" : "document 1", "color":"blue" }
{ "create":{"_index":"my_index","_id":2}}
{ "title" : "document 2", "color":"blue" }
{ "create":{"_index":"my_index","_id":3}}
{ "title" : "document 3", "color":"red" }
{ "create":{"_index":"my_index","_id":4}}
{ "title" : "document 4", "color":"red" }
{ "create":{"_index":"my_index","_id":5}}
{ "title" : "document 5", "color":"yellow" }
{ "create":{"_index":"my_index","_id":6}}
{ "title" : "document 6", "color":"yellow" }
{ "create":{"_index":"my_index","_id":7}}
{ "title" : "document 7", "color":"orange" }
{ "create":{"_index":"my_index","_id":8}}
{ "title" : "document 8", "color":"orange" }
{ "create":{"_index":"my_index","_id":9}}
{ "title" : "document 9", "color":"green" }
{ "create":{"_index":"my_index","_id":10}}
{ "title" : "document 10", "color":"green" }

{% include copy-curl.html %}

color 필드에서만 축소하는 파이프라인을 생성해요:

PUT /_search/pipeline/collapse_pipeline
{
  "response_processors": [
    {
      "collapse" : {
        "field": "color"
      }
    }
  ]
}

{% include copy-curl.html %}

검색 파이프라인 사용

이 예제에서는 color 필드로 축소하기 전에 상위 세 개 문서를 요청해요. 처음 두 문서의 color가 같기 때문에 두 번째 문서는 버려지고, 요청은 첫 번째와 세 번째 문서를 반환해요:

POST /my_index/_search?search_pipeline=collapse_pipeline
{
  "size": 3
}

{% include copy-curl.html %}

응답 {: .text-delta}
{
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 10,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "my_index",
        "_id" : "1",
        "_score" : 1.0,
        "_source" : {
          "title" : "document 1",
          "color" : "blue"
        }
      },
      {
        "_index" : "my_index",
        "_id" : "3",
        "_score" : 1.0,
        "_source" : {
          "title" : "document 3",
          "color" : "red"
        }
      }
    ]
  },
  "profile" : {
    "shards" : [ ]
  }
}

더 알아보기 (Learn more)