이름 있는 쿼리(named queries)

이름 있는 쿼리(named queries)

어떤 쿼리 절이든 _name 파라미터를 포함해 라벨을 붙일 수 있어요. 문서가 일치하면 응답에는 일치에 기여한 모든 쿼리 절의 이름을 나열하는 matched_queries 배열이 포함됩니다. 이는 주어진 문서와 일치한 복잡한 쿼리의 어떤 부분인지 식별하는 데 유용해요.

출처: 문서

본문

예제 (Example)

다음 쿼리는 bool 쿼리 안에 두 개의 이름 있는 match 절을 사용해요. 각 절은 스스로를 식별하는 _name을 가집니다.

GET opensearch_dashboards_sample_data_ecommerce/_search
{
  "size": 2,
  "_source": ["products.product_name", "customer_full_name"],
  "query": {
    "bool": {
      "should": [
        {"match": {"products.product_name": {"query": "shirt", "_name": "shirt_query"}}},
        {"match": {"products.product_name": {"query": "dress", "_name": "dress_query"}}}
      ]
    }
  }
}

예제 응답 (Example response)

각 히트의 matched_queries 배열은 해당 문서와 일치한 이름 있는 절을 보여줘요.

{
  "took": 16,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 1746,
      "relation": "eq"
    },
    "max_score": 1.8150847,
    "hits": [
      {
        "_index": "opensearch_dashboards_sample_data_ecommerce",
        "_id": "aoN5u50BpPQaFxRehbyq",
        "_score": 1.8150847,
        "_source": {
          "customer_full_name": "Stephanie Reyes",
          "products": [
            {
              "product_name": "Shirt - black/white"
            },
            {
              "product_name": "Cocktail dress / Party dress - navy"
            }
          ]
        },
        "matched_queries": [
          "shirt_query",
          "dress_query"
        ]
      },
      {
        "_index": "opensearch_dashboards_sample_data_ecommerce",
        "_id": "fYN5u50BpPQaFxRehLqd",
        "_score": 1.6545942,
        "_source": {
          "customer_full_name": "Clarice Daniels",
          "products": [
            {
              "product_name": "Summer dress - grey"
            },
            {
              "product_name": "Shirt - black/white"
            }
          ]
        },
        "matched_queries": [
          "shirt_query",
          "dress_query"
        ]
      }
    ]
  }
}

응답 본문 필드 (Response body fields)

다음 표는 이름 있는 쿼리에 특화된 응답 필드를 나열해요.

  • matched_queries: 이 문서와 일치한 모든 쿼리 절의 _name 값을 나열하는 문자열 배열이에요. 이름 있는 절이 하나 이상 일치할 때만 표시돼요.

더 알아보기 (Learn more)