Skip to content

Script: Metadata for update context #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 42 commits into
base: ingest_ctx_map_field_prop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
9b4dae5
WIP ingest update metadata
stu-elastic Jul 5, 2022
7d52c59
Create validators
stu-elastic Jul 6, 2022
158156d
Merge branch 'master' of github.com:stu-elastic/elasticsearch into in…
stu-elastic Jul 6, 2022
3fab662
revert "sourceAndMetadata" from "ingestContext"
stu-elastic Jul 6, 2022
205df38
revert "getContextMetadata" -> "getMetadata"
stu-elastic Jul 6, 2022
c35d5a7
Update javadoc
stu-elastic Jul 6, 2022
5fd7d3f
rest tests
stu-elastic Jul 6, 2022
bd3e4f2
Script: Metadata for update context
stu-elastic Jul 6, 2022
73e1743
add opValidator javadocs
stu-elastic Jul 6, 2022
0804227
Add hashcode for WriteableIngestDocumentTests.testFromXContent and le…
stu-elastic Jul 6, 2022
c86cd15
create is valid in scripts
stu-elastic Jul 6, 2022
4ee36ed
Pass valid ops
stu-elastic Jul 6, 2022
c9359d5
spotless UpdateSourceAndMetadata
stu-elastic Jul 6, 2022
7c35fc2
Update docs/changelog/88333.yaml
stu-elastic Jul 7, 2022
4cc8484
Improve error when sorting on incompatible types (#88399)
mayya-sharipova Jul 11, 2022
cf35640
Merge branch 'master' of github.com:stu-elastic/elasticsearch into in…
stu-elastic Jul 11, 2022
1f9ab49
Merge branch 'ingest_update_meta' of github.com:stu-elastic/elasticse…
stu-elastic Jul 11, 2022
20c8171
Merge branch 'ingest_update_meta' of github.com:stu-elastic/elasticse…
stu-elastic Jul 11, 2022
f4509db
Add UpdateCtxMap and UpsertCtxMap
stu-elastic Jul 11, 2022
fc3ec29
Merge branch 'ingest_ctx_map' of github.com:stu-elastic/elasticsearch…
stu-elastic Jul 11, 2022
b55a0bc
Fix test memory leak (#88362)
grcevski Jul 12, 2022
78244b7
Remove usages of TestGeoShapeFieldMapperPlugin from enrich module (#8…
iverase Jul 12, 2022
dd1bd83
Don't index geo_shape field in AbstractBuilderTestCase (#88437)
iverase Jul 12, 2022
47510ad
Reduce map lookups (#88418)
idegtiarenko Jul 12, 2022
9ebbe1c
Make ClusterInfo use immutable maps in all cases (#88447)
original-brownbear Jul 12, 2022
a4ec9c6
Correct some typos/mistakes in comments/docs (#88446)
pxsalehi Jul 12, 2022
ecc9605
[TSDB] Cache rollup bucket timestamp to reduce rounding cost (#88420)
weizijun Jul 12, 2022
4889650
Pass IndexMetadata to AllocationDecider.can_remain (#88453)
original-brownbear Jul 12, 2022
a2ee4c5
Polish reworked LoggedExec task (#88424)
breskeby Jul 12, 2022
c56715f
Updatable API keys - logging audit trail event (#88276)
n1v0lg Jul 12, 2022
5628b87
Bound random negative size test in SearchSourceBuilderTests#testNegat…
matschaffer Jul 12, 2022
24d2520
Audit API key ID when create or grant API keys (#88456)
ywangd Jul 12, 2022
3ed549b
TSDB: RollupShardIndexer logging improvements (#88416)
weizijun Jul 12, 2022
4af02b8
Stop registering TestGeoShapeFieldMapperPlugin in ESIntegTestCase (#8…
iverase Jul 12, 2022
47ecd20
Use consistent shard map type in IndexService (#88465)
original-brownbear Jul 12, 2022
67cacde
Corrected an incomplete sentence. (#86542)
local-ghost-127 Jul 12, 2022
28048a5
Updatable API keys - noop check (#88346)
n1v0lg Jul 12, 2022
bb95041
unmute test (#88454)
jakelandis Jul 12, 2022
1e07915
INFO logging of snapshot restore and completion (#88257)
kingherc Jul 12, 2022
84af493
Fix ReactiveStorageDeciderServiceTests testNodeSizeForDataBelowLowWat…
original-brownbear Jul 12, 2022
ba46bd4
Avoid noisy exceptions on data nodes when aborting snapshots (#88476)
original-brownbear Jul 12, 2022
ba171f2
Merge branch 'master' of github.com:stu-elastic/elasticsearch into in…
stu-elastic Jul 12, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class LoggedExecFuncTest extends AbstractGradleFuncTest {
import org.elasticsearch.gradle.LoggedExec
tasks.register('loggedExec', LoggedExec) {
commandLine 'ls', '-lh'
spoolOutput = $spooling
getSpoolOutput().set($spooling)
}
"""
when:
Expand All @@ -54,7 +54,7 @@ class LoggedExecFuncTest extends AbstractGradleFuncTest {
import org.elasticsearch.gradle.LoggedExec
tasks.register('loggedExec', LoggedExec) {
commandLine 'ls', 'wtf'
spoolOutput = $spooling
getSpoolOutput().set($spooling)
}
"""
when:
Expand Down Expand Up @@ -97,7 +97,7 @@ class LoggedExecFuncTest extends AbstractGradleFuncTest {
tasks.register('loggedExec', LoggedExec) {
commandLine 'echo', 'HELLO'
getCaptureOutput().set(true)
spoolOutput = true
getSpoolOutput().set(true)
}
"""
when:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public abstract class LoggedExec extends DefaultTask implements FileSystemOperat
protected FileSystemOperations fileSystemOperations;
private ProjectLayout projectLayout;
private ExecOperations execOperations;
private boolean spoolOutput;

@Input
@Optional
Expand Down Expand Up @@ -84,6 +83,9 @@ public abstract class LoggedExec extends DefaultTask implements FileSystemOperat
@Input
abstract public Property<File> getWorkingDir();

@Internal
abstract public Property<Boolean> getSpoolOutput();

private String output;

@Inject
Expand All @@ -95,14 +97,16 @@ public LoggedExec(ProjectLayout projectLayout, ExecOperations execOperations, Fi
// For now mimic default behaviour of Gradle Exec task here
getEnvironment().putAll(System.getenv());
getCaptureOutput().convention(false);
getSpoolOutput().convention(false);
}

@TaskAction
public void run() {
boolean spoolOutput = getSpoolOutput().get();
if (spoolOutput && getCaptureOutput().get()) {
throw new GradleException("Capturing output is not supported when spoolOutput is true.");
}
if (getCaptureOutput().getOrElse(false) && getIndentingConsoleOutput().isPresent()) {
if (getCaptureOutput().get() && getIndentingConsoleOutput().isPresent()) {
throw new GradleException("Capturing output is not supported when indentingConsoleOutput is configured.");
}
Consumer<Logger> outputLogger;
Expand Down Expand Up @@ -156,7 +160,9 @@ public void run() {
if (getLogger().isInfoEnabled() == false) {
if (exitValue != 0) {
try {
getLogger().error("Output for " + getExecutable().get() + ":");
if (getIndentingConsoleOutput().isPresent() == false) {
getLogger().error("Output for " + getExecutable().get() + ":");
}
outputLogger.accept(getLogger());
} catch (Exception e) {
throw new GradleException("Failed to read exec output", e);
Expand All @@ -173,10 +179,6 @@ private String byteStreamToString(OutputStream out) {
return ((ByteArrayOutputStream) out).toString(StandardCharsets.UTF_8);
}

public void setSpoolOutput(boolean spoolOutput) {
this.spoolOutput = spoolOutput;
}

public static ExecResult exec(ExecOperations execOperations, Action<ExecSpec> action) {
return genericExec(execOperations::exec, action);
}
Expand Down
6 changes: 6 additions & 0 deletions docs/changelog/88257.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 88257
summary: INFO logging of snapshot restore and completion
area: Snapshot/Restore
type: enhancement
issues:
- 86610
5 changes: 5 additions & 0 deletions docs/changelog/88276.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 88276
summary: Updatable API keys - logging audit trail event
area: Audit
type: enhancement
issues: []
5 changes: 5 additions & 0 deletions docs/changelog/88333.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 88333
summary: "Script: Metadata for update context"
area: Infra/Scripting
type: enhancement
issues: []
5 changes: 5 additions & 0 deletions docs/changelog/88346.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 88346
summary: Updatable API keys - noop check
area: Security
type: enhancement
issues: []
6 changes: 6 additions & 0 deletions docs/changelog/88399.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 88399
summary: Improve error when sorting on incompatible types
area: Search
type: enhancement
issues:
- 73146
5 changes: 5 additions & 0 deletions docs/changelog/88456.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 88456
summary: Audit API key ID when create or grant API keys
area: Audit
type: enhancement
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<titleabbrev>Avg</titleabbrev>
++++

A `single-value` metrics aggregation that computes the average of numeric values that are extracted from the aggregated documents. These values can be extracted either from specific numeric fields in the documents.
A `single-value` metrics aggregation that computes the average of numeric values that are extracted from the aggregated documents. These values can be extracted either from specific numeric or <<histogram,histogram>> fields in the documents.

Assuming the data consists of documents representing exams grades (between 0
and 100) of students we can average their scores with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ public void testRenameAtomicOperationSetFails() throws Exception {
Map<String, Object> metadata = new HashMap<>();
metadata.put("list", Collections.singletonList("item"));

IngestDocument ingestDocument = TestIngestDocument.ofMetadataWithValidator(metadata, Map.of("new_field", (k, v) -> {
IngestDocument ingestDocument = TestIngestDocument.ofMetadataWithValidator(metadata, Map.of("new_field", (o, k, v) -> {
if (v != null) {
throw new UnsupportedOperationException();
}
}, "list", (k, v) -> {}));
}, "list", (o, k, v) -> {}));
Processor processor = createRenameProcessor("list", "new_field", false);
try {
processor.execute(ingestDocument);
Expand All @@ -160,7 +160,7 @@ public void testRenameAtomicOperationRemoveFails() throws Exception {
Map<String, Object> metadata = new HashMap<>();
metadata.put("list", Collections.singletonList("item"));

IngestDocument ingestDocument = TestIngestDocument.ofMetadataWithValidator(metadata, Map.of("list", (k, v) -> {
IngestDocument ingestDocument = TestIngestDocument.ofMetadataWithValidator(metadata, Map.of("list", (o, k, v) -> {
if (v == null) {
throw new UnsupportedOperationException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,17 @@ class org.elasticsearch.painless.api.Json {
String dump(def)
String dump(def, boolean)
}

class org.elasticsearch.script.Metadata {
String getIndex()
String getId()
String getRouting()
long getVersion()
String getOp()
void setOp(String)
ZonedDateTime getTimestamp()
}

class org.elasticsearch.script.UpdateScript {
Metadata metadata()
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,47 @@
- match: { error.root_cause.0.type: "illegal_argument_exception" }
- match: { error.type: "illegal_argument_exception" }
- match: { error.reason: "Iterable object is self-referencing itself" }

---
"Script Update Metadata":
- skip:
version: " - 8.3.99"
reason: "update metadata introduced in 8.4.0"

- do:
update:
index: test_1
id: "2"
body:
script:
source: "ctx._source.bar = metadata().id + '-extra'"
lang: "painless"
upsert: {}
scripted_upsert: true

- do:
get:
index: test_1
id: "2"

- match: { _source.bar: 2-extra }
- match: { found: true }

- do:
update:
index: test_1
id: "2"
body:
script:
source: "metadata().op = 'delete'"
lang: "painless"
upsert: {}
scripted_upsert: true

- do:
catch: missing
get:
index: test_1
id: "2"

- match: { found: false }
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,97 @@
id: "4"

- match: { _source.within_one_minute: true }

---
"Script Upsert Metadata":
- skip:
version: " - 8.3.99"
reason: "update metadata introduced in 8.4.0"

- do:
catch: /routing is unavailable for insert/
update:
index: test_1
id: "1"
body:
script:
source: "ctx._source.foo = metadata().routing"
lang: "painless"
upsert: {}
scripted_upsert: true

- do:
update:
index: test_1
id: "2"
body:
script:
source: "ctx._source.foo = metadata().index + '_1'; ctx._source.bar = 'nothing'"
lang: "painless"
upsert: {}
scripted_upsert: true

- do:
get:
index: test_1
id: "2"

- match: { _source.foo: test_1_1 }
- match: { _source.bar: nothing }

- do:
update:
index: test_1
id: "3"
body:
script:
source: "metadata().op = 'noop'; ctx._source.bar = 'skipped?'"
lang: "painless"
upsert: {}
scripted_upsert: true

- do:
catch: missing
get:
index: test_1
id: "3"

- match: { found: false }

- do:
update:
index: test_1
id: "3"
body:
script:
source: "metadata().op = 'create'; ctx._source.bar = 'skipped?'"
lang: "painless"
upsert: {}
scripted_upsert: true

- do:
get:
index: test_1
id: "3"

- match: { found: true }
- match: { _source.bar: "skipped?" }

# update
- do:
update:
index: test_1
id: "2"
body:
script:
source: "ctx._source.bar = metadata().op + '-extra'"
lang: "painless"
upsert: {}
scripted_upsert: true

- do:
get:
index: test_1
id: "2"

- match: { _source.bar: index-extra }
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@

public class GeoBoundingBoxQueryLegacyGeoShapeIT extends GeoBoundingBoxQueryIntegTestCase {

@Override
protected boolean addMockGeoShapeFieldMapper() {
return false;
}

@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
return Collections.singleton(TestLegacyGeoShapeFieldMapperPlugin.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@

public class LegacyGeoShapeIT extends GeoShapeIntegTestCase {

@Override
protected boolean addMockGeoShapeFieldMapper() {
return false;
}

@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
return Collections.singleton(TestLegacyGeoShapeFieldMapperPlugin.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.elasticsearch.index.query.SearchExecutionContext;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.AbstractQueryTestCase;
import org.elasticsearch.test.TestGeoShapeFieldMapperPlugin;

import java.io.IOException;
import java.util.ArrayList;
Expand Down Expand Up @@ -54,7 +53,7 @@ protected void initializeAdditionalMappings(MapperService mapperService) throws

@Override
protected Collection<Class<? extends Plugin>> getPlugins() {
return Arrays.asList(MapperExtrasPlugin.class, TestGeoShapeFieldMapperPlugin.class);
return Arrays.asList(MapperExtrasPlugin.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.elasticsearch.join.ParentJoinPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.search.aggregations.BaseAggregationTestCase;
import org.elasticsearch.test.TestGeoShapeFieldMapperPlugin;

import java.util.Arrays;
import java.util.Collection;
Expand All @@ -20,7 +19,7 @@ public class ChildrenTests extends BaseAggregationTestCase<ChildrenAggregationBu

@Override
protected Collection<Class<? extends Plugin>> getPlugins() {
return Arrays.asList(ParentJoinPlugin.class, TestGeoShapeFieldMapperPlugin.class);
return Arrays.asList(ParentJoinPlugin.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.elasticsearch.join.ParentJoinPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.search.aggregations.BaseAggregationTestCase;
import org.elasticsearch.test.TestGeoShapeFieldMapperPlugin;

import java.util.Arrays;
import java.util.Collection;
Expand All @@ -20,7 +19,7 @@ public class ParentTests extends BaseAggregationTestCase<ParentAggregationBuilde

@Override
protected Collection<Class<? extends Plugin>> getPlugins() {
return Arrays.asList(ParentJoinPlugin.class, TestGeoShapeFieldMapperPlugin.class);
return Arrays.asList(ParentJoinPlugin.class);
}

@Override
Expand Down
Loading