forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This creates `.emit()` methods on a few primitive things for `keyword` and `date` style runtime fields. Now you can do stuff like: ``` "d": { "type": "date", "script": "'2020-01-18T17:41:34.000Z'.emit()" } ``` We get to piggy back of painless's dynamic dispatch code to regonize that you are in a `date` and trying to emit a `String` so we can "do the right thing" without any extra runtime cost. In this case we just parse the date using the `formatter` on the field. And since the example above doesn't use a formatter we get ISO8601, the date format of kings. Similarly, you can do stuff like: ``` "s": { "type": "keyword", "script": """ for (int i = 0; i < 100; i++) { i.emit(); } """ } ``` Painless *knows* `i` is an `int` and will call an emit method that emits its string value. Also! Assuming we get the syntax proposed in elastic#68088, because this is a chain of method invocations you can do something like: ``` "i": { "type": "long", "script": """ grok('%{NUMBER:i} %{NUMBER:j}').extract(doc['message'].value)?.i?.emit() """ } ``` This should be read as "if grok matches the message and extracts a value for `i` then emit it to the runtime field." If either the grok doesn't match or doesn't extract an `i` value then nothing will be emitted. As an extra nice thing - we'll automatilly convert whatever the `grok` expression outputs into a `long`. All of it handled for us using painless's standard dynamic dispatch code.
- Loading branch information
Showing
28 changed files
with
1,024 additions
and
214 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
...s/spi/src/main/java/org/elasticsearch/painless/spi/annotation/InjectScriptAnnotation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.painless.spi.annotation; | ||
|
||
/** | ||
* Inject the script itself into a method call. Only allowed on augmentations. | ||
*/ | ||
public class InjectScriptAnnotation { | ||
public static final String NAME = "inject_script"; | ||
} |
37 changes: 37 additions & 0 deletions
37
...src/main/java/org/elasticsearch/painless/spi/annotation/InjectScriptAnnotationParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.painless.spi.annotation; | ||
|
||
import java.util.Map; | ||
|
||
public class InjectScriptAnnotationParser implements WhitelistAnnotationParser { | ||
|
||
public static final InjectScriptAnnotationParser INSTANCE = new InjectScriptAnnotationParser(); | ||
|
||
private InjectScriptAnnotationParser() {} | ||
|
||
@Override | ||
public Object parse(Map<String, String> arguments) { | ||
if (false == arguments.isEmpty()) { | ||
throw new IllegalArgumentException("[@inject_script] can no have parameters"); | ||
} | ||
return new InjectScriptAnnotation(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.