-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Make wildcard accessible from the scripting field API #82763
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7553f79
Make wildcard accessible from the scripting fields API
jdconrad 0ac218f
Merge branch 'master' into wildcard
jdconrad a2e4610
Update docs/changelog/82763.yaml
jdconrad b5a4435
fix naming in tests
jdconrad 5ab373f
response to pr comments
jdconrad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,5 @@ | ||
| pr: 82763 | ||
| summary: Make wildcard accessible from the scripting field API | ||
| area: Infra/Scripting | ||
| type: enhancement | ||
| issues: [] |
This file contains hidden or 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 hidden or 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 hidden or 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
18 changes: 18 additions & 0 deletions
18
...lugin/wildcard/src/main/java/org/elasticsearch/xpack/wildcard/WildcardDocValuesField.java
This file contains hidden or 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,18 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.wildcard; | ||
|
|
||
| import org.elasticsearch.index.fielddata.SortedBinaryDocValues; | ||
| import org.elasticsearch.script.field.AbstractKeywordDocValuesField; | ||
|
|
||
| public class WildcardDocValuesField extends AbstractKeywordDocValuesField { | ||
|
|
||
| public WildcardDocValuesField(SortedBinaryDocValues input, String name) { | ||
| super(input, name); | ||
| } | ||
| } |
37 changes: 37 additions & 0 deletions
37
...in/wildcard/src/main/java/org/elasticsearch/xpack/wildcard/WildcardPainlessExtension.java
This file contains hidden or 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 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.wildcard; | ||
|
|
||
| import org.elasticsearch.painless.spi.PainlessExtension; | ||
| import org.elasticsearch.painless.spi.Whitelist; | ||
| import org.elasticsearch.painless.spi.WhitelistLoader; | ||
| import org.elasticsearch.script.ScriptContext; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import static java.util.Collections.singletonList; | ||
| import static org.elasticsearch.script.ScriptModule.CORE_CONTEXTS; | ||
|
|
||
| public class WildcardPainlessExtension implements PainlessExtension { | ||
| private static final Whitelist WHITELIST = WhitelistLoader.loadFromResourceFiles( | ||
| WildcardPainlessExtension.class, | ||
| "org.elasticsearch.xpack.wildcard.txt" | ||
| ); | ||
|
|
||
| @Override | ||
| public Map<ScriptContext<?>, List<Whitelist>> getContextWhitelists() { | ||
| List<Whitelist> whitelist = singletonList(WHITELIST); | ||
| Map<ScriptContext<?>, List<Whitelist>> contextWhitelists = new HashMap<>(CORE_CONTEXTS.size()); | ||
| for (ScriptContext<?> scriptContext : CORE_CONTEXTS.values()) { | ||
| contextWhitelists.put(scriptContext, whitelist); | ||
| } | ||
| return contextWhitelists; | ||
| } | ||
| } |
This file contains hidden or 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
1 change: 1 addition & 0 deletions
1
...ard/src/main/resources/META-INF/services/org.elasticsearch.painless.spi.PainlessExtension
This file contains hidden or 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 @@ | ||
| org.elasticsearch.xpack.wildcard.WildcardPainlessExtension |
10 changes: 10 additions & 0 deletions
10
.../src/main/resources/org/elasticsearch/xpack/wildcard/org.elasticsearch.xpack.wildcard.txt
This file contains hidden or 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,10 @@ | ||
| # | ||
| # Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| # or more contributor license agreements. Licensed under the Elastic License | ||
| # 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
| # in compliance with, at your election, the Elastic License 2.0 or the Server | ||
| # Side Public License, v 1. | ||
| # | ||
|
|
||
| class org.elasticsearch.xpack.wildcard.WildcardDocValuesField @dynamic_type { | ||
| } |
27 changes: 27 additions & 0 deletions
27
...src/yamlRestTest/java/org/elasticsearch/xpack/wildcard/WildcardClientYamlTestSuiteIT.java
This file contains hidden or 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 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.wildcard; | ||
|
|
||
| import com.carrotsearch.randomizedtesting.annotations.Name; | ||
| import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; | ||
|
|
||
| import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; | ||
| import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; | ||
|
|
||
| /** Runs yaml rest tests */ | ||
| public class WildcardClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { | ||
|
|
||
| public WildcardClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) { | ||
| super(testCandidate); | ||
| } | ||
|
|
||
| @ParametersFactory | ||
| public static Iterable<Object[]> parameters() throws Exception { | ||
| return ESClientYamlSuiteTestCase.createParameters(); | ||
| } | ||
| } |
49 changes: 49 additions & 0 deletions
49
x-pack/plugin/wildcard/src/yamlRestTest/resources/rest-api-spec/test/10_script_values.yml
This file contains hidden or 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,49 @@ | ||
| setup: | ||
| - do: | ||
| indices.create: | ||
| index: test | ||
| body: | ||
| settings: | ||
| number_of_shards: 1 | ||
| mappings: | ||
| properties: | ||
| test_wc: | ||
| type: wildcard | ||
|
|
||
| - do: | ||
| bulk: | ||
| index: test | ||
| refresh: true | ||
| body: | | ||
| { "index": {"_id" : "1"} } | ||
| { "test_wc": "abc" } | ||
| { "index": {"_id" : "2"} } | ||
| { "test_wc": ["adc", "aec"] } | ||
|
|
||
| --- | ||
| "Wildcard Fields API": | ||
| - do: | ||
| search: | ||
| index: test | ||
| body: | ||
| query: | ||
| wildcard: | ||
| test_wc: | ||
| value: "a*c" | ||
| script_fields: | ||
| constOne: | ||
| script: | ||
| source: "/* avoid stash */ $('test_wc', 'dne')" | ||
| constTwo: | ||
| script: | ||
| source: "field('test_wc').get(0, 'dne') + field('test_wc').get(1, 'xyz')" | ||
| constThree: | ||
| script: | ||
| source: "String s = ''; for (String z : field('test_wc')) s += z; return s" | ||
|
|
||
| - match: { hits.hits.0.fields.constOne.0: "abc" } | ||
| - match: { hits.hits.0.fields.constTwo.0: "abcxyz" } | ||
| - match: { hits.hits.0.fields.constThree.0: "abc" } | ||
| - match: { hits.hits.1.fields.constOne.0: "adc" } | ||
| - match: { hits.hits.1.fields.constTwo.0: "adcaec" } | ||
| - match: { hits.hits.1.fields.constThree.0: "adcaec" } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.