Skip to content

Commit 856dead

Browse files
github-actions[bot]kolchfa-awsnatebower
committed
adding wrapper dsl query docs (#9939)
* adding wrapper dsl query docs Signed-off-by: Anton Rubin <anton.rubin@eliatra.com> * adding changes to the docs Signed-off-by: Anton Rubin <anton.rubin@eliatra.com> * addressing the PR comments Signed-off-by: Anton Rubin <anton.rubin@eliatra.com> * Apply suggestions from code review Co-authored-by: kolchfa-aws <105444904+kolchfa-aws@users.noreply.github.com> Signed-off-by: AntonEliatra <anton.rubin@eliatra.com> * Update _query-dsl/specialized/wrapper.md Signed-off-by: Nathan Bower <nbower@amazon.com> --------- Signed-off-by: Anton Rubin <anton.rubin@eliatra.com> Signed-off-by: AntonEliatra <anton.rubin@eliatra.com> Signed-off-by: Nathan Bower <nbower@amazon.com> Co-authored-by: kolchfa-aws <105444904+kolchfa-aws@users.noreply.github.com> Co-authored-by: Nathan Bower <nbower@amazon.com> (cherry picked from commit 5f2acf3) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 1808407 commit 856dead

File tree

2 files changed

+97
-1
lines changed

2 files changed

+97
-1
lines changed

_query-dsl/specialized/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ OpenSearch supports the following specialized queries:
2828

2929
- [`script_score`]({{site.url}}{{site.baseurl}}/query-dsl/specialized/script-score/): Calculates a custom score for matching documents using a script.
3030

31-
- `wrapper`: Accepts other queries as JSON or YAML strings.
31+
- [`wrapper`]({{site.url}}{{site.baseurl}}/query-dsl/specialized/wrapper/): Accepts other queries as JSON or YAML strings.

_query-dsl/specialized/wrapper.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
---
2+
3+
layout: default
4+
title: Wrapper
5+
parent: Specialized queries
6+
nav_order: 80
7+
---
8+
9+
# Wrapper
10+
11+
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.
12+
13+
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.
14+
15+
## Example
16+
17+
Create an index named `products` with the following mappings:
18+
19+
```json
20+
PUT /products
21+
{
22+
"mappings": {
23+
"properties": {
24+
"title": { "type": "text" }
25+
}
26+
}
27+
}
28+
```
29+
{% include copy-curl.html %}
30+
31+
Index sample documents:
32+
33+
```json
34+
POST /products/_bulk
35+
{ "index": { "_id": 1 } }
36+
{ "title": "Wireless headphones with noise cancellation" }
37+
{ "index": { "_id": 2 } }
38+
{ "title": "Bluetooth speaker" }
39+
{ "index": { "_id": 3 } }
40+
{ "title": "Over-ear headphones with rich bass" }
41+
```
42+
{% include copy-curl.html %}
43+
44+
Encode the following query in Base64 format:
45+
46+
```bash
47+
echo -n '{ "match": { "title": "headphones" } }' | base64
48+
```
49+
{% include copy.html %}
50+
51+
Execute the encoded query:
52+
53+
```json
54+
POST /products/_search
55+
{
56+
"query": {
57+
"wrapper": {
58+
"query": "eyAibWF0Y2giOiB7ICJ0aXRsZSI6ICJoZWFkcGhvbmVzIiB9IH0="
59+
}
60+
}
61+
}
62+
```
63+
{% include copy-curl.html %}
64+
65+
The response contains the two matching documents:
66+
67+
```json
68+
{
69+
...
70+
"hits": {
71+
"total": {
72+
"value": 2,
73+
"relation": "eq"
74+
},
75+
"max_score": 0.20098841,
76+
"hits": [
77+
{
78+
"_index": "products",
79+
"_id": "1",
80+
"_score": 0.20098841,
81+
"_source": {
82+
"title": "Wireless headphones with noise cancellation"
83+
}
84+
},
85+
{
86+
"_index": "products",
87+
"_id": "3",
88+
"_score": 0.18459359,
89+
"_source": {
90+
"title": "Over-ear headphones with rich bass"
91+
}
92+
}
93+
]
94+
}
95+
}
96+
```

0 commit comments

Comments
 (0)