span_or 쿼리

span_or 쿼리

span_or 쿼리는 여러 span 쿼리를 결합해 해당 스팬들의 합집합을 매치해요. 포함된 span 쿼리 중 하나라도 일치하면 일치가 발생합니다.

예를 들어 span_or 쿼리를 사용해 다음을 할 수 있어요.

  • 여러 패턴 중 하나에 일치하는 스팬 찾기
  • 서로 다른 span 패턴을 대안으로 결합하기
  • 단일 쿼리로 여러 span 변형 매치하기

출처: 문서

본문

예제 (Example)

이 섹션의 예제를 실행하려면 설정(setup) 단계를 완료하세요.

다음 쿼리는 서로 2단어 안에 나타나는 "formal collar" 또는 "button collar"를 검색해요.

GET /clothing/_search
{
  "query": {
    "span_or": {
      "clauses": [
        {
          "span_near": {
            "clauses": [
              {
                "span_term": {
                  "description": "formal"
                }
              },
              {
                "span_term": {
                  "description": "collar"
                }
              }
            ],
            "slop": 0,
            "in_order": true
          }
        },
        {
          "span_near": {
            "clauses": [
              {
                "span_term": {
                  "description": "button"
                }
              },
              {
                "span_term": {
                  "description": "collar"
                }
              }
            ],
            "slop": 2,
            "in_order": true
          }
        }
      ]
    }
  }
}

이 쿼리는 지정된 slop 거리 안에서 문서 1("…formal collar…")과 문서 3("…button-down collar…")을 매치해요.

응답:

{
  "took": 4,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 2,
      "relation": "eq"
    },
    "max_score": 2.170027,
    "hits": [
      {
        "_index": "clothing",
        "_id": "1",
        "_score": 2.170027,
        "_source": {
          "description": "Long-sleeved dress shirt with a formal collar and button cuffs. "
        }
      },
      {
        "_index": "clothing",
        "_id": "3",
        "_score": 1.2509141,
        "_source": {
          "description": "Short-sleeved shirt with a button-down collar, can be dressed up or down."
        }
      }
    ]
  }
}

파라미터 (Parameters)

다음 표는 span_or 쿼리가 지원하는 모든 최상위 파라미터를 나열해요.

  • clauses (Array): 매치할 span 쿼리 배열이에요. 이 span 쿼리 중 하나라도 일치하면 쿼리가 일치해요. 최소한 하나의 span 쿼리를 포함해야 해요. 필수예요.

더 알아보기 (Learn more)