Skip to content

Commit f8782f3

Browse files
authored
Merge branch 'main' into mp/1
2 parents 8b236cb + 50d0474 commit f8782f3

File tree

101 files changed

+1951
-806
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+1951
-806
lines changed

build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/PublishPlugin.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ private void addNameAndDescriptionToPom(Project project, NamedDomainObjectSet<Ma
175175
private static void configureWithShadowPlugin(Project project, MavenPublication publication) {
176176
var shadow = project.getExtensions().getByType(ShadowExtension.class);
177177
shadow.component(publication);
178+
publication.artifact(project.getTasks().named("javadocJar"));
179+
publication.artifact(project.getTasks().named("sourcesJar"));
178180
}
179181

180182
private static void addScmInfo(XmlProvider xml, GitInfo gitInfo) {

docs/changelog/128866.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 128866
2+
summary: Add `age_in_millis` to ILM Explain Response
3+
area: ILM+SLM
4+
type: enhancement
5+
issues:
6+
- 103659

docs/changelog/129725.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 129725
2+
summary: Throw a 400 when sorting for all types of range fields
3+
area: Search
4+
type: bug
5+
issues: []
Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
---
2+
mapped_pages:
3+
- https://www.elastic.co/guide/en/elasticsearch/reference/8.18/docs-update.html
4+
applies_to:
5+
stack: all
6+
navigation_title: Update a document
7+
---
8+
9+
# Update a document [update-document]
10+
11+
The [Update API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-update) enables you to script document updates, allowing you to update, delete, or skip modifying a document.
12+
13+
The following examples show common use cases, such as incrementing a counter and adding or removing elements from a list, as well as how to:
14+
15+
- [Update part of a document](#update-part-document)
16+
- [Detect noop updates](#detect-noop-updates)
17+
- [Insert or update documents with upsert](#upsert)
18+
- [Simplify upsert with doc_as_upsert](#doc-as-upsert)
19+
20+
First, let's index a simple doc:
21+
22+
```console
23+
PUT test/_doc/1
24+
{
25+
"counter" : 1,
26+
"tags" : ["red"]
27+
}
28+
```
29+
% TESTSETUP
30+
31+
To increment the counter, you can submit an update request with the
32+
following script:
33+
34+
```console
35+
POST test/_update/1
36+
{
37+
"script" : {
38+
"source": "ctx._source.counter += params.count",
39+
"lang": "painless",
40+
"params" : {
41+
"count" : 4
42+
}
43+
}
44+
}
45+
```
46+
47+
Similarly, you could use and update script to add a tag to the list of tags
48+
(this is just a list, so the tag is added even it exists):
49+
50+
```console
51+
POST test/_update/1
52+
{
53+
"script": {
54+
"source": "ctx._source.tags.add(params.tag)",
55+
"lang": "painless",
56+
"params": {
57+
"tag": "blue"
58+
}
59+
}
60+
}
61+
```
62+
63+
You could also remove a tag from the list of tags. The Painless
64+
function to `remove` a tag takes the array index of the element
65+
you want to remove. To avoid a possible runtime error, you first need to
66+
make sure the tag exists. If the list contains duplicates of the tag, this
67+
script just removes one occurrence.
68+
69+
```console
70+
POST test/_update/1
71+
{
72+
"script": {
73+
"source": "if (ctx._source.tags.contains(params.tag)) { ctx._source.tags.remove(ctx._source.tags.indexOf(params.tag)) }",
74+
"lang": "painless",
75+
"params": {
76+
"tag": "blue"
77+
}
78+
}
79+
}
80+
```
81+
82+
You can also add and remove fields from a document. For example, this script
83+
adds the field `new_field`:
84+
85+
```console
86+
POST test/_update/1
87+
{
88+
"script" : "ctx._source.new_field = 'value_of_new_field'"
89+
}
90+
```
91+
92+
Conversely, this script removes the field `new_field`:
93+
94+
```console
95+
POST test/_update/1
96+
{
97+
"script" : "ctx._source.remove('new_field')"
98+
}
99+
```
100+
% TEST[continued]
101+
102+
The following script removes a subfield from an object field:
103+
104+
```console
105+
PUT test/_doc/1?refresh
106+
{
107+
"my-object": {
108+
"my-subfield": true
109+
}
110+
}
111+
```
112+
113+
```console
114+
POST test/_update/1
115+
{
116+
"script": "ctx._source['my-object'].remove('my-subfield')"
117+
}
118+
```
119+
% TEST[continued]
120+
121+
Instead of updating the document, you can also change the operation that is
122+
executed from within the script. For example, this request deletes the doc if
123+
the `tags` field contains `green`, otherwise it does nothing (`noop`):
124+
125+
```console
126+
POST test/_update/1
127+
{
128+
"script": {
129+
"source": "if (ctx._source.tags.contains(params.tag)) { ctx.op = 'delete' } else { ctx.op = 'noop' }",
130+
"lang": "painless",
131+
"params": {
132+
"tag": "green"
133+
}
134+
}
135+
}
136+
```
137+
138+
## Update part of a document [update-part-document]
139+
140+
The following partial update adds a new field to the
141+
existing document:
142+
143+
```console
144+
POST test/_update/1
145+
{
146+
"doc": {
147+
"name": "new_name"
148+
}
149+
}
150+
```
151+
152+
If both `doc` and `script` are specified, then `doc` is ignored. If you
153+
specify a scripted update, include the fields you want to update in the script.
154+
155+
156+
## Detect noop updates [detect-noop-updates]
157+
158+
By default updates that don't change anything detect that they don't change
159+
anything and return `"result": "noop"`:
160+
161+
```console
162+
POST test/_update/1
163+
{
164+
"doc": {
165+
"name": "new_name"
166+
}
167+
}
168+
```
169+
% TEST[continued]
170+
171+
If the value of `name` is already `new_name`, the update
172+
request is ignored and the `result` element in the response returns `noop`:
173+
174+
```console
175+
176+
{
177+
"_shards": {
178+
"total": 0,
179+
"successful": 0,
180+
"failed": 0
181+
},
182+
"_index": "test",
183+
"_id": "1",
184+
"_version": 2,
185+
"_primary_term": 1,
186+
"_seq_no": 1,
187+
"result": "noop"
188+
}
189+
```
190+
191+
You can disable this behavior by setting `"detect_noop": false`:
192+
193+
```console
194+
POST test/_update/1
195+
{
196+
"doc": {
197+
"name": "new_name"
198+
},
199+
"detect_noop": false
200+
}
201+
```
202+
203+
## Insert or update documents with upsert [upsert]
204+
205+
An upsert operation lets you update an existing document or insert a new one if it doesn't exist, in a single request.
206+
207+
In this example, if the product with ID `1` exists, its price will be updated to `100`. If the product does not exist, a new document with ID `1` and a price of `50` will be inserted.
208+
209+
```console
210+
POST /test/_update/1
211+
{
212+
"doc": {
213+
"product_price": 100
214+
},
215+
"upsert": {
216+
"product_price": 50
217+
}
218+
}
219+
```
220+
221+
## Run a scripted upsert [scripted-upsert]
222+
223+
To run the script whether or not the document exists, set `scripted_upsert` to
224+
`true`:
225+
226+
```console
227+
POST test/_update/1
228+
{
229+
"scripted_upsert": true,
230+
"script": {
231+
"source": """
232+
if ( ctx.op == 'create' ) {
233+
ctx._source.counter = params.count
234+
} else {
235+
ctx._source.counter += params.count
236+
}
237+
""",
238+
"params": {
239+
"count": 4
240+
}
241+
},
242+
"upsert": {}
243+
}
244+
```
245+
246+
## Simplify upsert with doc_as_upsert [doc-as-upsert]
247+
248+
Instead of sending a partial `doc` plus an `upsert` doc, you can set
249+
`doc_as_upsert` to `true` to use the contents of `doc` as the `upsert`
250+
value:
251+
252+
```console
253+
POST test/_update/1
254+
{
255+
"doc": {
256+
"name": "new_name"
257+
},
258+
"doc_as_upsert": true
259+
}
260+
```
261+
262+
::::{note}
263+
Using [ingest pipelines](https://www.elastic.co/guide/en/elasticsearch/reference/8.18/ingest.html) with `doc_as_upsert` is not supported.
264+
::::

docs/reference/elasticsearch/toc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ toc:
105105
- file: rest-apis/searching-with-query-rules.md
106106
- file: rest-apis/shard-request-cache.md
107107
- file: rest-apis/term-vectors-examples.md
108+
- file: rest-apis/update-document.md
108109
- file: rest-apis/update-cc-api-key-examples.md
109110
- file: rest-apis/vector-tile-search.md
110111
- file: mapping-reference/index.md

docs/reference/query-languages/esql/README.md

Lines changed: 83 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,95 @@ To help differentiate between the static and generated content, the generated co
105105
% This is generated by ESQL's AbstractFunctionTestCase. Do no edit it. See ../README.md for how to regenerate it.
106106
```
107107

108+
## Version differentiation in Docs V3
109+
110+
> [!IMPORTANT]
111+
> Starting with 9.0, we no longer publish separate documentation branches for every minor release (`9.0`, `9.1`, `9.2`, etc.).
112+
> This means there won't be a different page for `9.1`, `9.2`, and so on. Instead, all changes landing in subsequent minor releases **will appear on the same page**.
113+
114+
Because we now publish just one docs set off of the `main` branch, we use the [`applies_to` metadata](https://elastic.github.io/docs-builder/syntax/applies/) to differentiate features and their availability across different versions. This is a [cumulative approach](https://elastic.github.io/docs-builder/contribute/#cumulative-docs): instead of creating separate pages for each product and release, we update a **single page** with product- and version-specific details over time.
115+
116+
`applies_to` allows us to clearly communicate when features are introduced, when they transition from preview to GA, and which versions support specific functionality.
117+
118+
This metadata accepts a lifecycle and an optional version.
119+
120+
### Functions and operators
121+
122+
Use the `@FunctionAppliesTo` annotation within the `@FunctionInfo` annotation on function and operator classes to specify the lifecycle and version for functions and operators.
123+
124+
For example, to indicate that a function is in technical preview and applies to version 9.0.0, you would use:
125+
126+
```java
127+
@FunctionInfo(
128+
returnType = "boolean",
129+
appliesTo = {
130+
@FunctionAppliesTo(lifeCycle = FunctionAppliesToLifecycle.PREVIEW, version = "9.0.0")
131+
},
132+
...
133+
)
134+
```
135+
136+
When a feature evolves from preview in `9.0` to GA in `9.2`, add a new entry alongside the existing preview entry and remove the `preview = true` boolean:
137+
138+
```java
139+
@FunctionInfo(
140+
returnType = "boolean",
141+
preview = false, // the preview boolean can be removed (or flipped to false) when the function becomes GA
142+
appliesTo = {
143+
@FunctionAppliesTo(lifeCycle = FunctionAppliesToLifecycle.PREVIEW, version = "9.0.0"),
144+
@FunctionAppliesTo(lifeCycle = FunctionAppliesToLifecycle.GA, version = "9.2.0")
145+
},
146+
...
147+
)
148+
```
149+
150+
We updated [`DocsV3Support.java`](https://github.com/elastic/elasticsearch/blob/main/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/DocsV3Support.java) to generate the `applies_to` metadata correctly for functions and operators.
151+
152+
### Inline `applies_to` metadata
153+
154+
Use [inline annotations](https://elastic.github.io/docs-builder/syntax/applies/#inline-annotations) to specify `applies_to` metadata in descriptions, parameter lists, etc.
155+
156+
For example, the second item in this list is in technical preview as of version 9.2:
157+
158+
```markdown
159+
- Item 1
160+
- Item 2 {applies_to}`stack: preview 9.2.`
161+
```
162+
163+
### Key rules
164+
165+
1. **Use the `preview = true` boolean** for any tech preview feature - this is required for the Kibana inline docs
166+
- **Remove `preview = true`** only when the feature becomes GA on serverless and is _definitely_ going GA in the next minor release
167+
2. **Never delete `appliesTo` entries** - only add new ones as features evolve from preview to GA
168+
3. **Use specific versions** (`9.0.0`, `9.1.0`) when known, or just `PREVIEW` without a version if timing is uncertain
169+
4. **Add `applies_to` to examples** where necessary
170+
171+
> [!IMPORTANT]
172+
> We don't use `applies_to` in the legacy asciidoc system for 8.x and earlier versions.
173+
174+
### Supported lifecycles
175+
176+
- `PREVIEW` - Feature is in technical preview
177+
- `GA` - Feature is generally available
178+
- `DEPRECATED` - Feature is deprecated and will be removed in a future release
179+
- `UNAVAILABLE` - Feature is not available in the current version, but may be available in future releases
180+
181+
> [!NOTE]
182+
> Unreleased version information is automatically sanitized in the docs build output. For example, say you specify `preview 9.3.0`:
183+
> - Before `9.3.0` is released, the live documentation will display "Planned for a future release" instead of the specific version number.
184+
> - This will be updated automatically when the version is released.
185+
108186
## Tutorials
109187

110188
### Adding a new command
111189

112190
When adding a new command, for example adding the `CHANGE_POINT` command, do the following:
113191
1. Create a new file in the `_snippets/commands/layout` directory with the name of the command, for example `change_point.md`.
114-
2. Add the content for the command to the file. See other files in this directory for examples.
115-
3. Add the command to the list in `_snippets/lists/processing-commands.md`.
116-
4. Add an include directive to the `commands/processing-commands.md` file to include the new command.
117-
5. Add tested examples to the `_snippets/commands/examples` directory. See below for details.
192+
2. Ensure to specify what versions the command applies to. See [Version differentiation in Docs V3](#version-differentiation-in-docs-v3) for details. [Example PR](https://github.com/elastic/elasticsearch/pull/130314/files#diff-0ab90b6202c5d9eeea75dc95a7cb71dc4d720230342718bff887816771a5a803R3-R6).
193+
3. Add the content for the command to the file. See other files in this directory for examples.
194+
4. Add the command to the list in `_snippets/lists/processing-commands.md`.
195+
5. Add an include directive to the `commands/processing-commands.md` file to include the new command.
196+
6. Add tested examples to the `_snippets/commands/examples` directory. See below for details.
118197

119198
### Adding examples to commands
120199

0 commit comments

Comments
 (0)