You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[DOCS] Clarify Update API does not replace fields with sparse_vector field
Updated the documentation for `sparse_vector` fields to clarify merging behavior, replacement methods, and limitations.
🚗 Compiled all the admonitions into a limitations section
Copy file name to clipboardExpand all lines: docs/reference/elasticsearch/mapping-reference/sparse-vector.md
+67-12Lines changed: 67 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -220,24 +220,79 @@ GET my-index-000001/_search
220
220
}
221
221
```
222
222
223
-
::::{note}
224
-
`sparse_vector` fields can not be included in indices that were **created** on {{es}} versions between 8.0 and 8.10
225
-
::::
223
+
## Updating `sparse_vector` fields
226
224
225
+
When using the [Update API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-update) with the `doc` parameter, `sparse_vector` fields behave like nested objects and are **merged** rather than replaced. This means:
227
226
228
-
::::{note}
229
-
`sparse_vector` fields only support strictly positive values. Negative values will be rejected.
230
-
::::
227
+
- Existing tokens in the sparse vector are preserved
228
+
- New tokens are added
229
+
- Tokens present in both the existing and new data will have their values updated
231
230
231
+
This is different from primitive array fields (like `keyword`), which are replaced entirely during updates.
232
232
233
-
::::{note}
234
-
`sparse_vector` fields do not support [analyzers](docs-content://manage-data/data-store/text-analysis.md), querying, sorting or aggregating. They may only be used within specialized queries. The recommended query to use on these fields are [`sparse_vector`](/reference/query-languages/query-dsl/query-dsl-sparse-vector-query.md) queries. They may also be used within legacy [`text_expansion`](/reference/query-languages/query-dsl/query-dsl-text-expansion-query.md) queries.
235
-
::::
233
+
### Example of merging behavior
236
234
235
+
Original document:
237
236
238
-
::::{note}
239
-
`sparse_vector` fields only preserve 9 significant bits for the precision, which translates to a relative error of about 0.4%.
240
-
::::
237
+
```console
238
+
PUT /my-index/_doc/1
239
+
{
240
+
"my_vector": {
241
+
"token_a": 0.5,
242
+
"token_b": 0.8
243
+
}
244
+
}
245
+
```
246
+
247
+
Partial update:
248
+
249
+
```console
250
+
POST /my-index/_update/1
251
+
{
252
+
"doc": {
253
+
"my_vector": {
254
+
"token_c": 0.3
255
+
}
256
+
}
257
+
}
258
+
```
259
+
260
+
Observe that tokens are merged, not replaced:
261
+
262
+
```json
263
+
{
264
+
"my_vector": {
265
+
"token_a": 0.5,
266
+
"token_b": 0.8,
267
+
"token_c": 0.3
268
+
}
269
+
}
270
+
```
271
+
272
+
### Replacing the entire `sparse_vector` field
273
+
274
+
To replace the entire contents of a `sparse_vector` field, use a [script](docs-content://explore-analyze/scripting/modules-scripting-using.md) in your update request:
This same merging behavior also applies to [`rank_features` fields](/mapping-reference/rank-feature.md), as they are also object-like structures.
242
292
293
+
## Important notes and limitations
243
294
295
+
-`sparse_vector` fields can not be included in indices that were **created** on Elasticsearch versions between 8.0 and 8.10
296
+
-`sparse_vector` fields only support strictly positive values. Negative values will be rejected.
297
+
-`sparse_vector` fields do not support [analyzers](https://www.elastic.co/docs/manage-data/data-store/text-analysis), querying, sorting or aggregating. They may only be used within specialized queries. The recommended query to use on these fields are [`sparse_vector`](https://www.elastic.co/docs/reference/query-languages/query-dsl/query-dsl-sparse-vector-query) queries. They may also be used within legacy [`text_expansion`](https://www.elastic.co/docs/reference/query-languages/query-dsl/query-dsl-text-expansion-query) queries.
298
+
-`sparse_vector` fields only preserve 9 significant bits for the precision, which translates to a relative error of about 0.4%.
0 commit comments