Skip to content

Commit 2041922

Browse files
committed
peng - add doc
Signed-off-by: Jialiang Liang <jiallian@amazon.com>
1 parent b66f528 commit 2041922

1 file changed

Lines changed: 109 additions & 1 deletion

File tree

docs/user/ppl/interfaces/endpoint.md

Lines changed: 109 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,115 @@ Expected output:
5353
}
5454
```
5555

56-
## Explain
56+
## Highlight
57+
58+
### Description
59+
60+
You can include an optional `highlight` object in the request body to request search result highlighting. When a PPL query contains a full-text search (e.g., `search source=logs "error"`), OpenSearch identifies where the search terms appear in document fields and returns the matching fragments wrapped in the specified tags.
61+
62+
The `highlight` object supports the following parameters:
63+
64+
| Parameter | Type | Required | Description |
65+
|-----------|------|----------|-------------|
66+
| `fields` | Object | Yes | Map of field names to per-field configuration. Use `"*"` to highlight all `text` and `keyword` fields that match. |
67+
| `pre_tags` | Array of strings | No | Tags inserted before each highlighted term. Default: `["<em>"]`. |
68+
| `post_tags` | Array of strings | No | Tags inserted after each highlighted term. Default: `["</em>"]`. |
69+
| `fragment_size` | Integer | No | Maximum character length of each highlight fragment. Default is OpenSearch's default (100). Set to `2147483647` to return the entire field value without truncation. |
70+
71+
### What gets highlighted
72+
73+
- **Full-text search terms only.** The search term in `search source=logs "error"` is translated to a `query_string` query, and OpenSearch's highlighter identifies matches. Structured filters (`where`, `stats`, comparison operators) do not produce highlights.
74+
- **`text` and `keyword` fields only.** Numeric, date, boolean, and other non-string field types never produce highlight fragments.
75+
- **Wildcard field matching.** `"*": {}` matches all eligible fields, including `.keyword` subfields.
76+
77+
### Example 1: Wildcard highlight
78+
79+
```bash ppl
80+
curl -sS -H 'Content-Type: application/json' \
81+
-X POST localhost:9200/_plugins/_ppl \
82+
-d '{
83+
"query": "search source=accounts \"Holmes\"",
84+
"highlight": {
85+
"fields": { "*": {} },
86+
"pre_tags": ["<em>"],
87+
"post_tags": ["</em>"],
88+
"fragment_size": 2147483647
89+
}
90+
}'
91+
```
92+
93+
Expected output:
94+
95+
```json
96+
{
97+
"schema": [
98+
{ "name": "firstname", "type": "string" },
99+
{ "name": "lastname", "type": "string" },
100+
{ "name": "address", "type": "string" }
101+
],
102+
"datarows": [
103+
["Holmes", "Morgan", "123 Main St"],
104+
["Jane", "Holmes", "456 Oak Ave"],
105+
["John", "Smith", "880 Holmes Lane"]
106+
],
107+
"highlights": [
108+
{ "firstname": ["<em>Holmes</em>"], "firstname.keyword": ["<em>Holmes</em>"] },
109+
{ "lastname": ["<em>Holmes</em>"], "lastname.keyword": ["<em>Holmes</em>"] },
110+
{ "address": ["880 <em>Holmes</em> Lane"] }
111+
],
112+
"total": 3,
113+
"size": 3,
114+
"status": 200
115+
}
116+
```
117+
118+
### Example 2: Specific field with custom tags
119+
120+
```bash ppl
121+
curl -sS -H 'Content-Type: application/json' \
122+
-X POST localhost:9200/_plugins/_ppl \
123+
-d '{
124+
"query": "search source=accounts \"Holmes\"",
125+
"highlight": {
126+
"fields": { "address": {} },
127+
"pre_tags": ["<mark>"],
128+
"post_tags": ["</mark>"]
129+
}
130+
}'
131+
```
132+
133+
Expected output:
134+
135+
```json
136+
{
137+
"schema": [ ... ],
138+
"datarows": [ ... ],
139+
"highlights": [
140+
null,
141+
null,
142+
{ "address": ["880 <mark>Holmes</mark> Lane"] }
143+
],
144+
"total": 3,
145+
"size": 3,
146+
"status": 200
147+
}
148+
```
149+
150+
Only the `address` field is highlighted. Rows where "Holmes" appears in other fields have `null` highlight entries.
151+
152+
### Response format
153+
154+
- The `highlights` array is parallel to `datarows` — each entry corresponds to the row at the same index.
155+
- Entries are `null` when a row has no highlight data for the requested fields.
156+
- The `highlights` array is **omitted entirely** when no `highlight` config is provided in the request (backward compatible).
157+
158+
### Notes
159+
160+
- Highlighting is supported only in the Calcite engine.
161+
- The backend forwards the highlight config as-is to OpenSearch. The same highlighting behavior and limitations as [OpenSearch's highlighting API](https://opensearch.org/docs/latest/search-plugins/searching-data/highlight/) apply.
162+
- Piped commands (`where`, `sort`, `head`, `dedup`) narrow or reorder the result set but do not affect which terms are highlighted.
163+
164+
## Explain
57165

58166
### Description
59167

0 commit comments

Comments
 (0)