Link Search Menu Expand Document Documentation Menu

You're viewing version 3.1 of the OpenSearch documentation. This version is no longer maintained. For the latest version, see the current documentation. For information about OpenSearch version maintenance, see Release Schedule and Maintenance Policy.

Wrapper

The wrapper query lets you submit a complete query in Base64-encoded JSON format. It is useful when the query must be embedded in contexts that only support string values.

Use this query only when you need to manage system constraints. For readability and maintainability, it’s better to use standard JSON-based queries when possible.

Example

Create an index named products with the following mappings:

PUT /products
{
  "mappings": {
    "properties": {
      "title": { "type": "text" }
    }
  }
}

Index sample documents:

POST /products/_bulk
{ "index": { "_id": 1 } }
{ "title": "Wireless headphones with noise cancellation" }
{ "index": { "_id": 2 } }
{ "title": "Bluetooth speaker" }
{ "index": { "_id": 3 } }
{ "title": "Over-ear headphones with rich bass" }

Encode the following query in Base64 format:

echo -n '{ "match": { "title": "headphones" } }' | base64

Execute the encoded query:

POST /products/_search
{
  "query": {
    "wrapper": {
      "query": "eyAibWF0Y2giOiB7ICJ0aXRsZSI6ICJoZWFkcGhvbmVzIiB9IH0="
    }
  }
}

The response contains the two matching documents:

{
  ...
  "hits": {
    "total": {
      "value": 2,
      "relation": "eq"
    },
    "max_score": 0.20098841,
    "hits": [
      {
        "_index": "products",
        "_id": "1",
        "_score": 0.20098841,
        "_source": {
          "title": "Wireless headphones with noise cancellation"
        }
      },
      {
        "_index": "products",
        "_id": "3",
        "_score": 0.18459359,
        "_source": {
          "title": "Over-ear headphones with rich bass"
        }
      }
    ]
  }
}
350 characters left

Have a question? .

Want to contribute? or .