span_term 쿼리

span_term 쿼리

span_term 쿼리는 단일 용어를 포함하는 스팬을 매치하는 가장 기본적인 span 쿼리예요. 더 복잡한 span 쿼리의 구성 요소 역할을 합니다.

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

  • 다른 span 쿼리에서 사용할 수 있는 정확한 용어 일치 찾기
  • 위치 정보를 유지하면서 특정 단어 매치하기
  • 다른 span 쿼리와 결합할 수 있는 기본 스팬 만들기

출처: 문서

본문

예제 (Example)

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

다음 쿼리는 정확한 용어 "formal"을 검색해요.

GET /clothing/_search
{
  "query": {
    "span_term": {
      "description": "formal"
    }
  }
}

또는 value 파라미터에 검색 용어를 지정할 수도 있어요.

GET /clothing/_search
{
  "query": {
    "span_term": {
      "description": {
        "value": "formal"
      }
    }
  }
}

문서 점수를 높이기 위해 boost 값을 지정할 수도 있어요.

GET /clothing/_search
{
  "query": {
    "span_term": {
      "description": {
        "value": "formal",
        "boost": 2
      }
    }
  }
}

이 쿼리는 정확한 용어 "formal"을 포함하므로 문서 1과 문서 2를 매치해요. 위치 정보는 다른 span 쿼리에서 사용할 수 있도록 보존됩니다.

응답:

{
  "took": 2,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 2,
      "relation": "eq"
    },
    "max_score": 1.498922,
    "hits": [
      {
        "_index": "clothing",
        "_id": "2",
        "_score": 1.498922,
        "_source": {
          "description": "Beautiful long dress in red silk, perfect for formal events."
        }
      },
      {
        "_index": "clothing",
        "_id": "1",
        "_score": 1.4466847,
        "_source": {
          "description": "Long-sleeved dress shirt with a formal collar and button cuffs. "
        }
      }
    ]
  }
}

파라미터 (Parameters)

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

  • <field> (String 또는 object): 검색할 필드의 이름이에요.

더 알아보기 (Learn more)