Skip to content

Commit 5881322

Browse files
committed
Merge branch 'master' into ccr
* master: Cross-cluster search: preserve cluster alias in shard failures (#32608) Handle AlreadyClosedException when bumping primary term [TEST] Allow to run in FIPS JVM (#32607) [Test] Add ckb to the list of unsupported languages (#32611) SCRIPTING: Move Aggregation Scripts to their own context (#32068) Painless: Use LocalMethod Map For Lookup at Runtime (#32599) [TEST] Enhance failure message when bulk updates have failures [ML] Add ML result classes to protocol library (#32587) Suppress LicensingDocumentationIT.testPutLicense in release builds (#32613) [Rollup] Update wire version check after backport Suppress Wildfly test in FIPS JVMs (#32543) [Rollup] Improve ID scheme for rollup documents (#32558) ingest: doc: move Dot Expander Processor doc to correct position (#31743) [ML] Add some ML config classes to protocol library (#32502) [TEST]Split transport verification mode none tests (#32488) Core: Move helper date formatters over to java time (#32504) [Rollup] Remove builders from DateHistogramGroupConfig (#32555) [TEST} unmutes SearchAsyncActionTests and adds debugging info [ML] Add Detector config classes to protocol library (#32495) [Rollup] Remove builders from MetricConfig (#32536) Tests: Add rolling upgrade tests for watcher (#32428) Fix race between replica reset and primary promotion (#32442)
2 parents 3b739b9 + 826399f commit 5881322

File tree

153 files changed

+9033
-1324
lines changed

Some content is hidden

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

153 files changed

+9033
-1324
lines changed

client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/LicensingDocumentationIT.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
package org.elasticsearch.client.documentation;
2121

22-
import org.apache.lucene.util.LuceneTestCase.AwaitsFix;
22+
import org.elasticsearch.Build;
2323
import org.elasticsearch.action.ActionListener;
2424
import org.elasticsearch.action.LatchedActionListener;
2525
import org.elasticsearch.client.ESRestHighLevelClientTestCase;
@@ -41,10 +41,10 @@
4141
* Documentation for Licensing APIs in the high level java client.
4242
* Code wrapped in {@code tag} and {@code end} tags is included in the docs.
4343
*/
44-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/32580")
4544
public class LicensingDocumentationIT extends ESRestHighLevelClientTestCase {
4645

4746
public void testPutLicense() throws Exception {
47+
assumeTrue("License is only valid when tested against snapshot/test builds", Build.CURRENT.isSnapshot());
4848
RestHighLevelClient client = highLevelClient();
4949
String license = "{\"license\": {\"uid\":\"893361dc-9749-4997-93cb-802e3d7fa4a8\",\"type\":\"gold\"," +
5050
"\"issue_date_in_millis\":1411948800000,\"expiry_date_in_millis\":1914278399999,\"max_nodes\":1,\"issued_to\":\"issued_to\"," +

docs/reference/ingest/ingest-node.asciidoc

+119-119
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,125 @@ understands this to mean `2016-04-01` as is explained in the <<date-math-index-n
10491049
| `index_name_format` | no | yyyy-MM-dd | The format to be used when printing the parsed date into the index name. An valid Joda pattern is expected here.
10501050
|======
10511051

1052+
[[dot-expand-processor]]
1053+
=== Dot Expander Processor
1054+
1055+
Expands a field with dots into an object field. This processor allows fields
1056+
with dots in the name to be accessible by other processors in the pipeline.
1057+
Otherwise these <<accessing-data-in-pipelines,fields>> can't be accessed by any processor.
1058+
1059+
[[dot-expender-options]]
1060+
.Dot Expand Options
1061+
[options="header"]
1062+
|======
1063+
| Name | Required | Default | Description
1064+
| `field` | yes | - | The field to expand into an object field
1065+
| `path` | no | - | The field that contains the field to expand. Only required if the field to expand is part another object field, because the `field` option can only understand leaf fields.
1066+
|======
1067+
1068+
[source,js]
1069+
--------------------------------------------------
1070+
{
1071+
"dot_expander": {
1072+
"field": "foo.bar"
1073+
}
1074+
}
1075+
--------------------------------------------------
1076+
// NOTCONSOLE
1077+
1078+
For example the dot expand processor would turn this document:
1079+
1080+
[source,js]
1081+
--------------------------------------------------
1082+
{
1083+
"foo.bar" : "value"
1084+
}
1085+
--------------------------------------------------
1086+
// NOTCONSOLE
1087+
1088+
into:
1089+
1090+
[source,js]
1091+
--------------------------------------------------
1092+
{
1093+
"foo" : {
1094+
"bar" : "value"
1095+
}
1096+
}
1097+
--------------------------------------------------
1098+
// NOTCONSOLE
1099+
1100+
If there is already a `bar` field nested under `foo` then
1101+
this processor merges the `foo.bar` field into it. If the field is
1102+
a scalar value then it will turn that field into an array field.
1103+
1104+
For example, the following document:
1105+
1106+
[source,js]
1107+
--------------------------------------------------
1108+
{
1109+
"foo.bar" : "value2",
1110+
"foo" : {
1111+
"bar" : "value1"
1112+
}
1113+
}
1114+
--------------------------------------------------
1115+
// NOTCONSOLE
1116+
1117+
is transformed by the `dot_expander` processor into:
1118+
1119+
[source,js]
1120+
--------------------------------------------------
1121+
{
1122+
"foo" : {
1123+
"bar" : ["value1", "value2"]
1124+
}
1125+
}
1126+
--------------------------------------------------
1127+
// NOTCONSOLE
1128+
1129+
If any field outside of the leaf field conflicts with a pre-existing field of the same name,
1130+
then that field needs to be renamed first.
1131+
1132+
Consider the following document:
1133+
1134+
[source,js]
1135+
--------------------------------------------------
1136+
{
1137+
"foo": "value1",
1138+
"foo.bar": "value2"
1139+
}
1140+
--------------------------------------------------
1141+
// NOTCONSOLE
1142+
1143+
Then the `foo` needs to be renamed first before the `dot_expander`
1144+
processor is applied. So in order for the `foo.bar` field to properly
1145+
be expanded into the `bar` field under the `foo` field the following
1146+
pipeline should be used:
1147+
1148+
[source,js]
1149+
--------------------------------------------------
1150+
{
1151+
"processors" : [
1152+
{
1153+
"rename" : {
1154+
"field" : "foo",
1155+
"target_field" : "foo.bar""
1156+
}
1157+
},
1158+
{
1159+
"dot_expander": {
1160+
"field": "foo.bar"
1161+
}
1162+
}
1163+
]
1164+
}
1165+
--------------------------------------------------
1166+
// NOTCONSOLE
1167+
1168+
The reason for this is that Ingest doesn't know how to automatically cast
1169+
a scalar field to an object field.
1170+
10521171
[[fail-processor]]
10531172
=== Fail Processor
10541173
Raises an exception. This is useful for when
@@ -2058,125 +2177,6 @@ Converts a string to its uppercase equivalent.
20582177
--------------------------------------------------
20592178
// NOTCONSOLE
20602179

2061-
[[dot-expand-processor]]
2062-
=== Dot Expander Processor
2063-
2064-
Expands a field with dots into an object field. This processor allows fields
2065-
with dots in the name to be accessible by other processors in the pipeline.
2066-
Otherwise these <<accessing-data-in-pipelines,fields>> can't be accessed by any processor.
2067-
2068-
[[dot-expender-options]]
2069-
.Dot Expand Options
2070-
[options="header"]
2071-
|======
2072-
| Name | Required | Default | Description
2073-
| `field` | yes | - | The field to expand into an object field
2074-
| `path` | no | - | The field that contains the field to expand. Only required if the field to expand is part another object field, because the `field` option can only understand leaf fields.
2075-
|======
2076-
2077-
[source,js]
2078-
--------------------------------------------------
2079-
{
2080-
"dot_expander": {
2081-
"field": "foo.bar"
2082-
}
2083-
}
2084-
--------------------------------------------------
2085-
// NOTCONSOLE
2086-
2087-
For example the dot expand processor would turn this document:
2088-
2089-
[source,js]
2090-
--------------------------------------------------
2091-
{
2092-
"foo.bar" : "value"
2093-
}
2094-
--------------------------------------------------
2095-
// NOTCONSOLE
2096-
2097-
into:
2098-
2099-
[source,js]
2100-
--------------------------------------------------
2101-
{
2102-
"foo" : {
2103-
"bar" : "value"
2104-
}
2105-
}
2106-
--------------------------------------------------
2107-
// NOTCONSOLE
2108-
2109-
If there is already a `bar` field nested under `foo` then
2110-
this processor merges the `foo.bar` field into it. If the field is
2111-
a scalar value then it will turn that field into an array field.
2112-
2113-
For example, the following document:
2114-
2115-
[source,js]
2116-
--------------------------------------------------
2117-
{
2118-
"foo.bar" : "value2",
2119-
"foo" : {
2120-
"bar" : "value1"
2121-
}
2122-
}
2123-
--------------------------------------------------
2124-
// NOTCONSOLE
2125-
2126-
is transformed by the `dot_expander` processor into:
2127-
2128-
[source,js]
2129-
--------------------------------------------------
2130-
{
2131-
"foo" : {
2132-
"bar" : ["value1", "value2"]
2133-
}
2134-
}
2135-
--------------------------------------------------
2136-
// NOTCONSOLE
2137-
2138-
If any field outside of the leaf field conflicts with a pre-existing field of the same name,
2139-
then that field needs to be renamed first.
2140-
2141-
Consider the following document:
2142-
2143-
[source,js]
2144-
--------------------------------------------------
2145-
{
2146-
"foo": "value1",
2147-
"foo.bar": "value2"
2148-
}
2149-
--------------------------------------------------
2150-
// NOTCONSOLE
2151-
2152-
Then the `foo` needs to be renamed first before the `dot_expander`
2153-
processor is applied. So in order for the `foo.bar` field to properly
2154-
be expanded into the `bar` field under the `foo` field the following
2155-
pipeline should be used:
2156-
2157-
[source,js]
2158-
--------------------------------------------------
2159-
{
2160-
"processors" : [
2161-
{
2162-
"rename" : {
2163-
"field" : "foo",
2164-
"target_field" : "foo.bar""
2165-
}
2166-
},
2167-
{
2168-
"dot_expander": {
2169-
"field": "foo.bar"
2170-
}
2171-
}
2172-
]
2173-
}
2174-
--------------------------------------------------
2175-
// NOTCONSOLE
2176-
2177-
The reason for this is that Ingest doesn't know how to automatically cast
2178-
a scalar field to an object field.
2179-
21802180
[[urldecode-processor]]
21812181
=== URL Decode Processor
21822182
URL-decodes a string

modules/lang-expression/src/main/java/org/elasticsearch/script/expression/ExpressionScriptEngine.java

+50-5
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@
3434
import org.elasticsearch.common.settings.Settings;
3535
import org.elasticsearch.index.fielddata.IndexFieldData;
3636
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
37-
import org.elasticsearch.index.mapper.GeoPointFieldMapper.GeoPointFieldType;
3837
import org.elasticsearch.index.mapper.DateFieldMapper;
38+
import org.elasticsearch.index.mapper.GeoPointFieldMapper.GeoPointFieldType;
3939
import org.elasticsearch.index.mapper.MappedFieldType;
4040
import org.elasticsearch.index.mapper.MapperService;
41+
import org.elasticsearch.script.BucketAggregationScript;
42+
import org.elasticsearch.script.BucketAggregationSelectorScript;
4143
import org.elasticsearch.script.ClassPermission;
4244
import org.elasticsearch.script.ExecutableScript;
4345
import org.elasticsearch.script.FilterScript;
@@ -54,6 +56,7 @@
5456
import java.security.PrivilegedAction;
5557
import java.text.ParseException;
5658
import java.util.ArrayList;
59+
import java.util.HashMap;
5760
import java.util.List;
5861
import java.util.Map;
5962

@@ -112,6 +115,17 @@ protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundE
112115
} else if (context.instanceClazz.equals(ExecutableScript.class)) {
113116
ExecutableScript.Factory factory = (p) -> new ExpressionExecutableScript(expr, p);
114117
return context.factoryClazz.cast(factory);
118+
} else if (context.instanceClazz.equals(BucketAggregationScript.class)) {
119+
return context.factoryClazz.cast(newBucketAggregationScriptFactory(expr));
120+
} else if (context.instanceClazz.equals(BucketAggregationSelectorScript.class)) {
121+
BucketAggregationScript.Factory factory = newBucketAggregationScriptFactory(expr);
122+
BucketAggregationSelectorScript.Factory wrappedFactory = parameters -> new BucketAggregationSelectorScript(parameters) {
123+
@Override
124+
public boolean execute() {
125+
return factory.newInstance(getParams()).execute() == 1.0;
126+
}
127+
};
128+
return context.factoryClazz.cast(wrappedFactory);
115129
} else if (context.instanceClazz.equals(FilterScript.class)) {
116130
FilterScript.Factory factory = (p, lookup) -> newFilterScript(expr, lookup, p);
117131
return context.factoryClazz.cast(factory);
@@ -122,6 +136,37 @@ protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundE
122136
throw new IllegalArgumentException("expression engine does not know how to handle script context [" + context.name + "]");
123137
}
124138

139+
private static BucketAggregationScript.Factory newBucketAggregationScriptFactory(Expression expr) {
140+
return parameters -> {
141+
ReplaceableConstDoubleValues[] functionValuesArray =
142+
new ReplaceableConstDoubleValues[expr.variables.length];
143+
Map<String, ReplaceableConstDoubleValues> functionValuesMap = new HashMap<>();
144+
for (int i = 0; i < expr.variables.length; ++i) {
145+
functionValuesArray[i] = new ReplaceableConstDoubleValues();
146+
functionValuesMap.put(expr.variables[i], functionValuesArray[i]);
147+
}
148+
return new BucketAggregationScript(parameters) {
149+
@Override
150+
public double execute() {
151+
getParams().forEach((name, value) -> {
152+
ReplaceableConstDoubleValues placeholder = functionValuesMap.get(name);
153+
if (placeholder == null) {
154+
throw new IllegalArgumentException("Error using " + expr + ". " +
155+
"The variable [" + name + "] does not exist in the executable expressions script.");
156+
} else if (value instanceof Number == false) {
157+
throw new IllegalArgumentException("Error using " + expr + ". " +
158+
"Executable expressions scripts can only process numbers." +
159+
" The variable [" + name + "] is not a number.");
160+
} else {
161+
placeholder.setValue(((Number) value).doubleValue());
162+
}
163+
});
164+
return expr.evaluate(functionValuesArray);
165+
}
166+
};
167+
};
168+
}
169+
125170
private SearchScript.LeafFactory newSearchScript(Expression expr, SearchLookup lookup, @Nullable Map<String, Object> vars) {
126171
MapperService mapper = lookup.doc().mapperService();
127172
// NOTE: if we need to do anything complicated with bindings in the future, we can just extend Bindings,
@@ -267,7 +312,7 @@ public void setDocument(int docid) {
267312
};
268313
};
269314
}
270-
315+
271316
private ScoreScript.LeafFactory newScoreScript(Expression expr, SearchLookup lookup, @Nullable Map<String, Object> vars) {
272317
SearchScript.LeafFactory searchLeafFactory = newSearchScript(expr, lookup, vars);
273318
return new ScoreScript.LeafFactory() {
@@ -284,17 +329,17 @@ public ScoreScript newInstance(LeafReaderContext ctx) throws IOException {
284329
public double execute() {
285330
return script.runAsDouble();
286331
}
287-
332+
288333
@Override
289334
public void setDocument(int docid) {
290335
script.setDocument(docid);
291336
}
292-
337+
293338
@Override
294339
public void setScorer(Scorer scorer) {
295340
script.setScorer(scorer);
296341
}
297-
342+
298343
@Override
299344
public double get_score() {
300345
return script.getScore();

0 commit comments

Comments
 (0)