From 370f0b885e347c7659f60e78865ca40350b46ced Mon Sep 17 00:00:00 2001 From: Jun Ohtani Date: Thu, 22 Sep 2016 20:54:30 +0900 Subject: [PATCH 01/19] Removing request parameters in _analyze API Remove request params in _analyze API without index param Change rest-api-test using JSON Change docs using JSON Closes #20246 --- .../admin/indices/RestAnalyzeAction.java | 32 +---------- .../admin/indices/RestAnalyzeActionTests.java | 12 ++++- docs/plugins/analysis-icu.asciidoc | 15 ++++-- docs/plugins/analysis-kuromoji.asciidoc | 54 +++++++++++++++---- docs/plugins/analysis-phonetic.asciidoc | 6 ++- docs/reference/indices/analyze.asciidoc | 15 ------ .../mapping/params/analyzer.asciidoc | 6 ++- .../test/analysis_icu/10_basic.yaml | 26 +++++---- .../test/analysis_kuromoji/10_basic.yaml | 31 ++++++----- .../test/analysis_phonetic/10_metaphone.yaml | 5 +- .../20_double_metaphone.yaml | 5 +- .../analysis_phonetic/30_beider_morse.yaml | 5 +- .../analysis_phonetic/50_daitch_mokotoff.yaml | 5 +- .../test/analysis_smartcn/10_basic.yaml | 10 ++-- .../test/analysis_stempel/10_basic.yaml | 12 +++-- .../test/indices.analyze/10_analyze.yaml | 23 ++++---- 16 files changed, 144 insertions(+), 118 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestAnalyzeAction.java b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestAnalyzeAction.java index 247df1a380e..02ac7201fb3 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestAnalyzeAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestAnalyzeAction.java @@ -67,42 +67,14 @@ public class RestAnalyzeAction extends BaseRestHandler { @Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { - String[] texts = request.paramAsStringArrayOrEmptyIfAll("text"); - AnalyzeRequest analyzeRequest = new AnalyzeRequest(request.param("index")); - analyzeRequest.text(texts); - analyzeRequest.analyzer(request.param("analyzer")); - analyzeRequest.field(request.param("field")); - final String tokenizer = request.param("tokenizer"); - if (tokenizer != null) { - analyzeRequest.tokenizer(tokenizer); - } - for (String filter : request.paramAsStringArray("filter", Strings.EMPTY_ARRAY)) { - analyzeRequest.addTokenFilter(filter); - } - for (String charFilter : request.paramAsStringArray("char_filter", Strings.EMPTY_ARRAY)) { - analyzeRequest.addTokenFilter(charFilter); - } - analyzeRequest.explain(request.paramAsBoolean("explain", false)); - analyzeRequest.attributes(request.paramAsStringArray("attributes", analyzeRequest.attributes())); - if (RestActions.hasBodyContent(request)) { - XContentType type = RestActions.guessBodyContentType(request); - if (type == null) { - if (texts == null || texts.length == 0) { - texts = new String[]{ RestActions.getRestContent(request).utf8ToString() }; - analyzeRequest.text(texts); - } - } else { - // NOTE: if rest request with xcontent body has request parameters, the parameters does not override xcontent values - buildFromContent(RestActions.getRestContent(request), analyzeRequest, parseFieldMatcher); - } - } + buildFromContent(RestActions.getRestContent(request), analyzeRequest, parseFieldMatcher); return channel -> client.admin().indices().analyze(analyzeRequest, new RestToXContentListener<>(channel)); } - public static void buildFromContent(BytesReference content, AnalyzeRequest analyzeRequest, ParseFieldMatcher parseFieldMatcher) { + static void buildFromContent(BytesReference content, AnalyzeRequest analyzeRequest, ParseFieldMatcher parseFieldMatcher) { try (XContentParser parser = XContentHelper.createParser(content)) { if (parser.nextToken() != XContentParser.Token.START_OBJECT) { throw new IllegalArgumentException("Malformed content, must start with an object"); diff --git a/core/src/test/java/org/elasticsearch/rest/action/admin/indices/RestAnalyzeActionTests.java b/core/src/test/java/org/elasticsearch/rest/action/admin/indices/RestAnalyzeActionTests.java index 9b7d4073d0d..980a76d12cb 100644 --- a/core/src/test/java/org/elasticsearch/rest/action/admin/indices/RestAnalyzeActionTests.java +++ b/core/src/test/java/org/elasticsearch/rest/action/admin/indices/RestAnalyzeActionTests.java @@ -19,16 +19,25 @@ package org.elasticsearch.rest.action.admin.indices; import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest; +import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.rest.RestChannel; +import org.elasticsearch.rest.RestRequest; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.test.rest.FakeRestRequest; + +import java.util.HashMap; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.startsWith; +import static org.mockito.Mockito.doCallRealMethod; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; public class RestAnalyzeActionTests extends ESTestCase { @@ -118,7 +127,7 @@ public class RestAnalyzeActionTests extends ESTestCase { assertThat(e.getMessage(), startsWith("explain must be either 'true' or 'false'")); } - public void testDeprecatedParamException() throws Exception { + public void testDeprecatedParamIn2xException() throws Exception { IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> RestAnalyzeAction.buildFromContent( XContentFactory.jsonBuilder() @@ -165,5 +174,4 @@ public class RestAnalyzeActionTests extends ESTestCase { , new AnalyzeRequest("for test"), new ParseFieldMatcher(Settings.EMPTY))); assertThat(e.getMessage(), startsWith("Unknown parameter [token_filter]")); } - } diff --git a/docs/plugins/analysis-icu.asciidoc b/docs/plugins/analysis-icu.asciidoc index 1677634bb56..5ea55d7437d 100644 --- a/docs/plugins/analysis-icu.asciidoc +++ b/docs/plugins/analysis-icu.asciidoc @@ -164,7 +164,11 @@ PUT icu_sample } } -POST icu_sample/_analyze?analyzer=my_analyzer&text=Elasticsearch. Wow! +POST icu_sample/_analyze +{ + "analyzer": "my_analyzer", + "text": "Elasticsearch. Wow!" +} -------------------------------------------------- // CONSOLE @@ -480,18 +484,21 @@ PUT icu_sample } } -GET icu_sample/_analyze?analyzer=latin +GET icu_sample/_analyze { + "analyzer": "latin", "text": "你好" <2> } -GET icu_sample/_analyze?analyzer=latin +GET icu_sample/_analyze { + "analyzer": "latin", "text": "здравствуйте" <3> } -GET icu_sample/_analyze?analyzer=latin +GET icu_sample/_analyze { + "analyzer": "latin", "text": "こんにちは" <4> } diff --git a/docs/plugins/analysis-kuromoji.asciidoc b/docs/plugins/analysis-kuromoji.asciidoc index 6b3dc0a72f1..44eab2f2329 100644 --- a/docs/plugins/analysis-kuromoji.asciidoc +++ b/docs/plugins/analysis-kuromoji.asciidoc @@ -175,7 +175,11 @@ PUT kuromoji_sample } } -POST kuromoji_sample/_analyze?analyzer=my_analyzer&text=東京スカイツリー +POST kuromoji_sample/_analyze +{ + "analyzer": "my_analyzer", + "text": "東京スカイツリー" +} -------------------------------------------------- // CONSOLE @@ -228,7 +232,11 @@ PUT kuromoji_sample } } -POST kuromoji_sample/_analyze?analyzer=my_analyzer&text=飲み +POST kuromoji_sample/_analyze +{ + "analyzer": "my_analyzer", + "text": "飲み" +} -------------------------------------------------- // CONSOLE @@ -290,7 +298,11 @@ PUT kuromoji_sample } } -POST kuromoji_sample/_analyze?analyzer=my_analyzer&text=寿司がおいしいね +POST kuromoji_sample/_analyze +{ + "analyzer": "my_analyzer", + "text": "寿司がおいしいね" +} -------------------------------------------------- // CONSOLE @@ -363,9 +375,17 @@ PUT kuromoji_sample } } -POST kuromoji_sample/_analyze?analyzer=katakana_analyzer&text=寿司 <1> +POST kuromoji_sample/_analyze +{ + "analyzer": "katakana_analyzer", + "text": "寿司" <1> +} -POST kuromoji_sample/_analyze?analyzer=romaji_analyzer&text=寿司 <2> +POST kuromoji_sample/_analyze +{ + "analyzer": "romaji_analyzer", + "text": "寿司" <2> +} -------------------------------------------------- // CONSOLE @@ -413,9 +433,17 @@ PUT kuromoji_sample } } -POST kuromoji_sample/_analyze?analyzer=my_analyzer&text=コピー <1> +POST kuromoji_sample/_analyze +{ + "analyzer": "my_analyzer", + "text": "コピー" <1> +} -POST kuromoji_sample/_analyze?analyzer=my_analyzer&text=サーバー <2> +POST kuromoji_sample/_analyze +{ + "analyzer": "my_analyzer", + "text": "サーバー" <2> +} -------------------------------------------------- // CONSOLE @@ -461,7 +489,11 @@ PUT kuromoji_sample } } -POST kuromoji_sample/_analyze?analyzer=analyzer_with_ja_stop&text=ストップは消える +POST kuromoji_sample/_analyze +{ + "analyzer": "analyzer_with_ja_stop", + "text": "ストップは消える" +} -------------------------------------------------- // CONSOLE @@ -507,7 +539,11 @@ PUT kuromoji_sample } } -POST kuromoji_sample/_analyze?analyzer=my_analyzer&text=一〇〇〇 +POST kuromoji_sample/_analyze +{ + "analyzer": "my_analyzer", + "text": "一〇〇〇" +} -------------------------------------------------- // CONSOLE diff --git a/docs/plugins/analysis-phonetic.asciidoc b/docs/plugins/analysis-phonetic.asciidoc index 0544900a8ca..fffbfcbd103 100644 --- a/docs/plugins/analysis-phonetic.asciidoc +++ b/docs/plugins/analysis-phonetic.asciidoc @@ -82,7 +82,11 @@ PUT phonetic_sample } } -POST phonetic_sample/_analyze?analyzer=my_analyzer&text=Joe Bloggs <1> +POST phonetic_sample/_analyze +{ + "analyzer": "my_analyzer", + "text": "Joe Bloggs" <1> +} -------------------------------------------------- // CONSOLE diff --git a/docs/reference/indices/analyze.asciidoc b/docs/reference/indices/analyze.asciidoc index dbb2c8f101a..0d9d60d4845 100644 --- a/docs/reference/indices/analyze.asciidoc +++ b/docs/reference/indices/analyze.asciidoc @@ -100,21 +100,6 @@ curl -XGET 'localhost:9200/test/_analyze' -d ' Will cause the analysis to happen based on the analyzer configured in the mapping for `obj1.field1` (and if not, the default index analyzer). -All parameters can also supplied as request parameters. For example: - -[source,js] --------------------------------------------------- -curl -XGET 'localhost:9200/_analyze?tokenizer=keyword&filter=lowercase&text=this+is+a+test' --------------------------------------------------- - -For backwards compatibility, we also accept the text parameter as the body of the request, -provided it doesn't start with `{` : - -[source,js] --------------------------------------------------- -curl -XGET 'localhost:9200/_analyze?tokenizer=keyword&filter=lowercase&char_filter=html_strip' -d 'this is a test' --------------------------------------------------- - === Explain Analyze If you want to get more advanced details, set `explain` to `true` (defaults to `false`). It will output all token attributes for each token. diff --git a/docs/reference/mapping/params/analyzer.asciidoc b/docs/reference/mapping/params/analyzer.asciidoc index c075b662805..0b60451e02a 100644 --- a/docs/reference/mapping/params/analyzer.asciidoc +++ b/docs/reference/mapping/params/analyzer.asciidoc @@ -60,13 +60,15 @@ PUT /my_index } } -GET my_index/_analyze?field=text <3> +GET my_index/_analyze <3> { + "field": "text", "text": "The quick Brown Foxes." } -GET my_index/_analyze?field=text.english <4> +GET my_index/_analyze <4> { + "field": "text.english", "text": "The quick Brown Foxes." } -------------------------------------------------- diff --git a/plugins/analysis-icu/src/test/resources/rest-api-spec/test/analysis_icu/10_basic.yaml b/plugins/analysis-icu/src/test/resources/rest-api-spec/test/analysis_icu/10_basic.yaml index 64fbbcadf7d..180f6c6f5b6 100644 --- a/plugins/analysis-icu/src/test/resources/rest-api-spec/test/analysis_icu/10_basic.yaml +++ b/plugins/analysis-icu/src/test/resources/rest-api-spec/test/analysis_icu/10_basic.yaml @@ -3,8 +3,9 @@ "Tokenizer": - do: indices.analyze: - text: Foo Bar - tokenizer: icu_tokenizer + body: + text: Foo Bar + tokenizer: icu_tokenizer - length: { tokens: 2 } - match: { tokens.0.token: Foo } - match: { tokens.1.token: Bar } @@ -12,26 +13,29 @@ "Normalization filter": - do: indices.analyze: - filter: icu_normalizer - text: Foo Bar Ruß - tokenizer: keyword + body: + filter: [icu_normalizer] + text: Foo Bar Ruß + tokenizer: keyword - length: { tokens: 1 } - match: { tokens.0.token: foo bar russ } --- "Normalization charfilter": - do: indices.analyze: - char_filter: icu_normalizer - text: Foo Bar Ruß - tokenizer: keyword + body: + char_filter: [icu_normalizer] + text: Foo Bar Ruß + tokenizer: keyword - length: { tokens: 1 } - match: { tokens.0.token: foo bar russ } --- "Folding filter": - do: indices.analyze: - filter: icu_folding - text: Foo Bar résumé - tokenizer: keyword + body: + filter: [icu_folding] + text: Foo Bar résumé + tokenizer: keyword - length: { tokens: 1 } - match: { tokens.0.token: foo bar resume } diff --git a/plugins/analysis-kuromoji/src/test/resources/rest-api-spec/test/analysis_kuromoji/10_basic.yaml b/plugins/analysis-kuromoji/src/test/resources/rest-api-spec/test/analysis_kuromoji/10_basic.yaml index 42df558567d..1cca2b728e0 100644 --- a/plugins/analysis-kuromoji/src/test/resources/rest-api-spec/test/analysis_kuromoji/10_basic.yaml +++ b/plugins/analysis-kuromoji/src/test/resources/rest-api-spec/test/analysis_kuromoji/10_basic.yaml @@ -4,8 +4,9 @@ "Analyzer": - do: indices.analyze: - text: JR新宿駅の近くにビールを飲みに行こうか - analyzer: kuromoji + body: + text: JR新宿駅の近くにビールを飲みに行こうか + analyzer: kuromoji - length: { tokens: 7 } - match: { tokens.0.token: jr } - match: { tokens.1.token: 新宿 } @@ -18,8 +19,9 @@ "Tokenizer": - do: indices.analyze: - text: 関西国際空港 - tokenizer: kuromoji_tokenizer + body: + text: 関西国際空港 + tokenizer: kuromoji_tokenizer - length: { tokens: 4 } - match: { tokens.0.token: 関西 } - match: { tokens.1.token: 関西国際空港 } @@ -29,26 +31,29 @@ "Baseform filter": - do: indices.analyze: - text: 飲み - tokenizer: kuromoji_tokenizer - filter: kuromoji_baseform + body: + text: 飲み + tokenizer: kuromoji_tokenizer + filter: [kuromoji_baseform] - length: { tokens: 1 } - match: { tokens.0.token: 飲む } --- "Reading filter": - do: indices.analyze: - text: 寿司 - tokenizer: kuromoji_tokenizer - filter: kuromoji_readingform + body: + text: 寿司 + tokenizer: kuromoji_tokenizer + filter: [kuromoji_readingform] - length: { tokens: 1 } - match: { tokens.0.token: スシ } --- "Stemming filter": - do: indices.analyze: - text: サーバー - tokenizer: kuromoji_tokenizer - filter: kuromoji_stemmer + body: + text: サーバー + tokenizer: kuromoji_tokenizer + filter: [kuromoji_stemmer] - length: { tokens: 1 } - match: { tokens.0.token: サーバ } diff --git a/plugins/analysis-phonetic/src/test/resources/rest-api-spec/test/analysis_phonetic/10_metaphone.yaml b/plugins/analysis-phonetic/src/test/resources/rest-api-spec/test/analysis_phonetic/10_metaphone.yaml index 02d4b315b6e..1f326fe3776 100644 --- a/plugins/analysis-phonetic/src/test/resources/rest-api-spec/test/analysis_phonetic/10_metaphone.yaml +++ b/plugins/analysis-phonetic/src/test/resources/rest-api-spec/test/analysis_phonetic/10_metaphone.yaml @@ -22,8 +22,9 @@ - do: indices.analyze: index: phonetic_sample - analyzer: my_analyzer - text: Joe Bloggs + body: + analyzer: my_analyzer + text: Joe Bloggs - length: { tokens: 4 } - match: { tokens.0.token: J } diff --git a/plugins/analysis-phonetic/src/test/resources/rest-api-spec/test/analysis_phonetic/20_double_metaphone.yaml b/plugins/analysis-phonetic/src/test/resources/rest-api-spec/test/analysis_phonetic/20_double_metaphone.yaml index 675847e557e..5af9f48aa80 100644 --- a/plugins/analysis-phonetic/src/test/resources/rest-api-spec/test/analysis_phonetic/20_double_metaphone.yaml +++ b/plugins/analysis-phonetic/src/test/resources/rest-api-spec/test/analysis_phonetic/20_double_metaphone.yaml @@ -22,8 +22,9 @@ - do: indices.analyze: index: phonetic_sample - analyzer: my_analyzer - text: supercalifragilisticexpialidocious + body: + analyzer: my_analyzer + text: supercalifragilisticexpialidocious - length: { tokens: 1 } - match: { tokens.0.token: SPRKLF } diff --git a/plugins/analysis-phonetic/src/test/resources/rest-api-spec/test/analysis_phonetic/30_beider_morse.yaml b/plugins/analysis-phonetic/src/test/resources/rest-api-spec/test/analysis_phonetic/30_beider_morse.yaml index 015610af172..259b0adea74 100644 --- a/plugins/analysis-phonetic/src/test/resources/rest-api-spec/test/analysis_phonetic/30_beider_morse.yaml +++ b/plugins/analysis-phonetic/src/test/resources/rest-api-spec/test/analysis_phonetic/30_beider_morse.yaml @@ -24,8 +24,9 @@ - do: indices.analyze: index: phonetic_sample - analyzer: my_analyzer - text: Szwarc + body: + analyzer: my_analyzer + text: Szwarc - length: { tokens: 1 } - match: { tokens.0.token: Svarts } diff --git a/plugins/analysis-phonetic/src/test/resources/rest-api-spec/test/analysis_phonetic/50_daitch_mokotoff.yaml b/plugins/analysis-phonetic/src/test/resources/rest-api-spec/test/analysis_phonetic/50_daitch_mokotoff.yaml index 5125ae3d684..c67b6892bc9 100644 --- a/plugins/analysis-phonetic/src/test/resources/rest-api-spec/test/analysis_phonetic/50_daitch_mokotoff.yaml +++ b/plugins/analysis-phonetic/src/test/resources/rest-api-spec/test/analysis_phonetic/50_daitch_mokotoff.yaml @@ -21,8 +21,9 @@ - do: indices.analyze: index: phonetic_sample - analyzer: my_analyzer - text: Moskowitz + body: + analyzer: my_analyzer + text: Moskowitz - length: { tokens: 1 } - match: { tokens.0.token: "645740" } diff --git a/plugins/analysis-smartcn/src/test/resources/rest-api-spec/test/analysis_smartcn/10_basic.yaml b/plugins/analysis-smartcn/src/test/resources/rest-api-spec/test/analysis_smartcn/10_basic.yaml index 2549f774f81..0f1b2805c93 100644 --- a/plugins/analysis-smartcn/src/test/resources/rest-api-spec/test/analysis_smartcn/10_basic.yaml +++ b/plugins/analysis-smartcn/src/test/resources/rest-api-spec/test/analysis_smartcn/10_basic.yaml @@ -3,8 +3,9 @@ "Tokenizer": - do: indices.analyze: - text: 我购买了道具和服装。 - tokenizer: smartcn_tokenizer + body: + text: 我购买了道具和服装。 + tokenizer: smartcn_tokenizer - length: { tokens: 7 } - match: { tokens.0.token: 我 } - match: { tokens.1.token: 购买 } @@ -17,8 +18,9 @@ "Analyzer": - do: indices.analyze: - text: 我购买了道具和服装。 - analyzer: smartcn + body: + text: 我购买了道具和服装。 + analyzer: smartcn - length: { tokens: 6 } - match: { tokens.0.token: 我 } - match: { tokens.1.token: 购买 } diff --git a/plugins/analysis-stempel/src/test/resources/rest-api-spec/test/analysis_stempel/10_basic.yaml b/plugins/analysis-stempel/src/test/resources/rest-api-spec/test/analysis_stempel/10_basic.yaml index f87f00b7922..1941126c64f 100644 --- a/plugins/analysis-stempel/src/test/resources/rest-api-spec/test/analysis_stempel/10_basic.yaml +++ b/plugins/analysis-stempel/src/test/resources/rest-api-spec/test/analysis_stempel/10_basic.yaml @@ -3,16 +3,18 @@ "Stemmer": - do: indices.analyze: - text: studenci - tokenizer: keyword - filter: polish_stem + body: + text: studenci + tokenizer: keyword + filter: [polish_stem] - length: { tokens: 1 } - match: { tokens.0.token: student } --- "Analyzer": - do: indices.analyze: - text: studenta był - analyzer: polish + body: + text: studenta był + analyzer: polish - length: { tokens: 1 } - match: { tokens.0.token: student } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.analyze/10_analyze.yaml b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.analyze/10_analyze.yaml index 35d4a2b5222..268cd781289 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.analyze/10_analyze.yaml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.analyze/10_analyze.yaml @@ -8,7 +8,8 @@ setup: "Basic test": - do: indices.analyze: - text: Foo Bar + body: + text: Foo Bar - length: { tokens: 2 } - match: { tokens.0.token: foo } - match: { tokens.1.token: bar } @@ -17,9 +18,10 @@ setup: "Tokenizer and filter": - do: indices.analyze: - filter: lowercase - text: Foo Bar - tokenizer: keyword + body: + filter: [lowercase] + text: Foo Bar + tokenizer: keyword - length: { tokens: 1 } - match: { tokens.0.token: foo bar } @@ -38,9 +40,10 @@ setup: - do: indices.analyze: - field: text index: test - text: Foo Bar! + body: + field: text + text: Foo Bar! - length: { tokens: 2 } - match: { tokens.0.token: Foo } - match: { tokens.1.token: Bar! } @@ -52,14 +55,6 @@ setup: - length: {tokens: 1 } - match: { tokens.0.token: foo bar } --- -"Body params override query string": - - do: - indices.analyze: - text: Foo Bar - body: { "text": "Bar Foo", "filter": ["lowercase"], "tokenizer": keyword } - - length: {tokens: 1 } - - match: { tokens.0.token: bar foo } ---- "Array text": - do: indices.analyze: From eca9894c5f27e6189f5974f6215e26833dfdd65e Mon Sep 17 00:00:00 2001 From: Jun Ohtani Date: Sat, 1 Oct 2016 05:42:45 +0900 Subject: [PATCH 02/19] Removing request parameters in _analyze API Remove unused imports Replace POST method by GET method in docs Add breaking changes explanation Fix small issue in Kuromoji docs Closes #20246 --- .../admin/indices/RestAnalyzeAction.java | 2 -- .../admin/indices/RestAnalyzeActionTests.java | 9 -------- docs/plugins/analysis-icu.asciidoc | 2 +- docs/plugins/analysis-kuromoji.asciidoc | 22 +++++++++---------- docs/plugins/analysis-phonetic.asciidoc | 2 +- .../migration/migrate_6_0/rest.asciidoc | 4 ++++ 6 files changed, 17 insertions(+), 24 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestAnalyzeAction.java b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestAnalyzeAction.java index 02ac7201fb3..1390e9d771d 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestAnalyzeAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestAnalyzeAction.java @@ -22,13 +22,11 @@ import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParseFieldMatcher; -import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; diff --git a/core/src/test/java/org/elasticsearch/rest/action/admin/indices/RestAnalyzeActionTests.java b/core/src/test/java/org/elasticsearch/rest/action/admin/indices/RestAnalyzeActionTests.java index 980a76d12cb..385bfd17b1d 100644 --- a/core/src/test/java/org/elasticsearch/rest/action/admin/indices/RestAnalyzeActionTests.java +++ b/core/src/test/java/org/elasticsearch/rest/action/admin/indices/RestAnalyzeActionTests.java @@ -19,25 +19,16 @@ package org.elasticsearch.rest.action.admin.indices; import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest; -import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentFactory; -import org.elasticsearch.rest.RestChannel; -import org.elasticsearch.rest.RestRequest; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.test.rest.FakeRestRequest; - -import java.util.HashMap; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.startsWith; -import static org.mockito.Mockito.doCallRealMethod; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; public class RestAnalyzeActionTests extends ESTestCase { diff --git a/docs/plugins/analysis-icu.asciidoc b/docs/plugins/analysis-icu.asciidoc index 5ea55d7437d..7ba57f9df4f 100644 --- a/docs/plugins/analysis-icu.asciidoc +++ b/docs/plugins/analysis-icu.asciidoc @@ -164,7 +164,7 @@ PUT icu_sample } } -POST icu_sample/_analyze +GET icu_sample/_analyze { "analyzer": "my_analyzer", "text": "Elasticsearch. Wow!" diff --git a/docs/plugins/analysis-kuromoji.asciidoc b/docs/plugins/analysis-kuromoji.asciidoc index 44eab2f2329..80823938fa8 100644 --- a/docs/plugins/analysis-kuromoji.asciidoc +++ b/docs/plugins/analysis-kuromoji.asciidoc @@ -175,7 +175,7 @@ PUT kuromoji_sample } } -POST kuromoji_sample/_analyze +GET kuromoji_sample/_analyze { "analyzer": "my_analyzer", "text": "東京スカイツリー" @@ -232,7 +232,7 @@ PUT kuromoji_sample } } -POST kuromoji_sample/_analyze +GET kuromoji_sample/_analyze { "analyzer": "my_analyzer", "text": "飲み" @@ -298,7 +298,7 @@ PUT kuromoji_sample } } -POST kuromoji_sample/_analyze +GET kuromoji_sample/_analyze { "analyzer": "my_analyzer", "text": "寿司がおいしいね" @@ -375,13 +375,13 @@ PUT kuromoji_sample } } -POST kuromoji_sample/_analyze +GET kuromoji_sample/_analyze { "analyzer": "katakana_analyzer", "text": "寿司" <1> } -POST kuromoji_sample/_analyze +GET kuromoji_sample/_analyze { "analyzer": "romaji_analyzer", "text": "寿司" <2> @@ -433,13 +433,13 @@ PUT kuromoji_sample } } -POST kuromoji_sample/_analyze +GET kuromoji_sample/_analyze { "analyzer": "my_analyzer", "text": "コピー" <1> } -POST kuromoji_sample/_analyze +GET kuromoji_sample/_analyze { "analyzer": "my_analyzer", "text": "サーバー" <2> @@ -452,7 +452,7 @@ POST kuromoji_sample/_analyze [[analysis-kuromoji-stop]] -===== `ja_stop` token filter +==== `ja_stop` token filter The `ja_stop` token filter filters out Japanese stopwords (`_japanese_`), and any other custom stopwords specified by the user. This filter only supports @@ -489,7 +489,7 @@ PUT kuromoji_sample } } -POST kuromoji_sample/_analyze +GET kuromoji_sample/_analyze { "analyzer": "analyzer_with_ja_stop", "text": "ストップは消える" @@ -514,7 +514,7 @@ The above request returns: // TESTRESPONSE [[analysis-kuromoji-number]] -===== `kuromoji_number` token filter +==== `kuromoji_number` token filter The `kuromoji_number` token filter normalizes Japanese numbers (kansūji) to regular Arabic decimal numbers in half-width characters. For example: @@ -539,7 +539,7 @@ PUT kuromoji_sample } } -POST kuromoji_sample/_analyze +GET kuromoji_sample/_analyze { "analyzer": "my_analyzer", "text": "一〇〇〇" diff --git a/docs/plugins/analysis-phonetic.asciidoc b/docs/plugins/analysis-phonetic.asciidoc index fffbfcbd103..7f50679a9a1 100644 --- a/docs/plugins/analysis-phonetic.asciidoc +++ b/docs/plugins/analysis-phonetic.asciidoc @@ -82,7 +82,7 @@ PUT phonetic_sample } } -POST phonetic_sample/_analyze +GET phonetic_sample/_analyze { "analyzer": "my_analyzer", "text": "Joe Bloggs" <1> diff --git a/docs/reference/migration/migrate_6_0/rest.asciidoc b/docs/reference/migration/migrate_6_0/rest.asciidoc index 1e02df1f61f..a19933a8c3c 100644 --- a/docs/reference/migration/migrate_6_0/rest.asciidoc +++ b/docs/reference/migration/migrate_6_0/rest.asciidoc @@ -7,3 +7,7 @@ In previous versions of Elasticsearch, JSON documents were allowed to contain un This feature was removed in the 5.x series, but a backwards-compability layer was added via the system property `elasticsearch.json.allow_unquoted_field_names`. This backwards-compability layer has been removed in Elasticsearch 6.0.0. + +==== Analyze API changes + +The deprecated request parameters and plain text in request body has been removed, use JSON in request body. From 99236b76270d53f6cbe0870a93ae1986acdd2b6a Mon Sep 17 00:00:00 2001 From: Jun Ohtani Date: Sun, 2 Oct 2016 04:23:07 +0900 Subject: [PATCH 03/19] Removing request parameters in _analyze API Fix small English issue in breaking changes Closes #20246 --- docs/reference/migration/migrate_6_0/rest.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reference/migration/migrate_6_0/rest.asciidoc b/docs/reference/migration/migrate_6_0/rest.asciidoc index a19933a8c3c..74974969e43 100644 --- a/docs/reference/migration/migrate_6_0/rest.asciidoc +++ b/docs/reference/migration/migrate_6_0/rest.asciidoc @@ -10,4 +10,4 @@ has been removed in Elasticsearch 6.0.0. ==== Analyze API changes -The deprecated request parameters and plain text in request body has been removed, use JSON in request body. +The deprecated request parameters and plain text in request body has been removed. Use JSON in request body. From 945fa499d223261fffc89c732f340ad112ae58d7 Mon Sep 17 00:00:00 2001 From: Jun Ohtani Date: Wed, 5 Oct 2016 19:13:33 +0900 Subject: [PATCH 04/19] Deprecating request parameters in _analyze API Remove params in indices.analyze.json Fix REST changes Closes #20246 --- .../migration/migrate_6_0/rest.asciidoc | 2 +- .../rest-api-spec/api/indices.analyze.json | 34 +------------------ 2 files changed, 2 insertions(+), 34 deletions(-) diff --git a/docs/reference/migration/migrate_6_0/rest.asciidoc b/docs/reference/migration/migrate_6_0/rest.asciidoc index 74974969e43..7e2c0cb1cae 100644 --- a/docs/reference/migration/migrate_6_0/rest.asciidoc +++ b/docs/reference/migration/migrate_6_0/rest.asciidoc @@ -10,4 +10,4 @@ has been removed in Elasticsearch 6.0.0. ==== Analyze API changes -The deprecated request parameters and plain text in request body has been removed. Use JSON in request body. +The deprecated request parameters and plain text in request body has been removed. Define parameters in request body. diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/indices.analyze.json b/rest-api-spec/src/main/resources/rest-api-spec/api/indices.analyze.json index 881382ffa00..93965388916 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/indices.analyze.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/indices.analyze.json @@ -12,22 +12,6 @@ } }, "params": { - "analyzer": { - "type" : "string", - "description" : "The name of the analyzer to use" - }, - "char_filter": { - "type" : "list", - "description" : "A comma-separated list of character filters to use for the analysis" - }, - "field": { - "type" : "string", - "description" : "Use the analyzer configured for this field (instead of passing the analyzer name)" - }, - "filter": { - "type" : "list", - "description" : "A comma-separated list of filters to use for the analysis" - }, "index": { "type" : "string", "description" : "The name of the index to scope the operation" @@ -36,22 +20,6 @@ "type" : "boolean", "description" : "With `true`, specify that a local shard should be used if available, with `false`, use a random shard (default: true)" }, - "text": { - "type" : "list", - "description" : "The text on which the analysis should be performed (when request body is not used)" - }, - "tokenizer": { - "type" : "string", - "description" : "The name of the tokenizer to use for the analysis" - }, - "explain": { - "type" : "boolean", - "description" : "With `true`, outputs more advanced details. (default: false)" - }, - "attributes": { - "type" : "list", - "description" : "A comma-separated list of token attributes to output, this parameter works only with `explain=true`" - }, "format": { "type": "enum", "options" : ["detailed","text"], @@ -61,7 +29,7 @@ } }, "body": { - "description" : "The text on which the analysis should be performed" + "description" : "Define analyzer/tokenizer parameters and the text on which the analysis should be performed" } } } From ab22307cf28736ce6133aa994d23f7ed584d021f Mon Sep 17 00:00:00 2001 From: Greg Marzouka Date: Mon, 24 Oct 2016 15:06:17 -0400 Subject: [PATCH 05/19] Remove allow_no_indices from indices.upgrade --- .../src/main/resources/rest-api-spec/api/indices.upgrade.json | 4 ---- 1 file changed, 4 deletions(-) diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/indices.upgrade.json b/rest-api-spec/src/main/resources/rest-api-spec/api/indices.upgrade.json index 66111456719..f83cf255165 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/indices.upgrade.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/indices.upgrade.json @@ -12,10 +12,6 @@ } }, "params": { - "allow_no_indices": { - "type" : "boolean", - "description" : "Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified)" - }, "expand_wildcards": { "type" : "enum", "options" : ["open","closed","none","all"], From b89c5aff51cfbb24c31bd067e6094b0bd5c857c9 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 25 Oct 2016 08:19:10 -0400 Subject: [PATCH 06/19] Add preformatted tags to Javadoc in OsProbe This commit adds preformatted tags to the Javadoc for OsProbe#readSysFsCgroupCpuAcctCpuStat to render the form of the cpu.stat file in a fixed-width font. --- core/src/main/java/org/elasticsearch/monitor/os/OsProbe.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/src/main/java/org/elasticsearch/monitor/os/OsProbe.java b/core/src/main/java/org/elasticsearch/monitor/os/OsProbe.java index 6d264afb6c7..ef8d8521ad7 100644 --- a/core/src/main/java/org/elasticsearch/monitor/os/OsProbe.java +++ b/core/src/main/java/org/elasticsearch/monitor/os/OsProbe.java @@ -400,9 +400,11 @@ public class OsProbe { * {@code cpu} subsystem. These lines represent the CPU time * statistics and have the form *

+ *

      * nr_periods \d+
      * nr_throttled \d+
      * throttled_time \d+
+     * 
*

* where {@code nr_periods} is the number of period intervals * as specified by {@code cpu.cfs_period_us} that have elapsed, From 1bc08ff1e53eb0c18fa5ed288c4b399839e3310d Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 25 Oct 2016 08:33:15 -0400 Subject: [PATCH 07/19] Fix empty

tag warning in o/e/m/o/OsProbe.java This commit fixes an empty

tag warning in o/e/m/o/OsProbe.java. --- .../src/main/java/org/elasticsearch/monitor/os/OsProbe.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/monitor/os/OsProbe.java b/core/src/main/java/org/elasticsearch/monitor/os/OsProbe.java index ef8d8521ad7..f2195732db3 100644 --- a/core/src/main/java/org/elasticsearch/monitor/os/OsProbe.java +++ b/core/src/main/java/org/elasticsearch/monitor/os/OsProbe.java @@ -399,13 +399,11 @@ public class OsProbe { * group to which the Elasticsearch process belongs for the * {@code cpu} subsystem. These lines represent the CPU time * statistics and have the form - *

- *

+     * 
      * nr_periods \d+
      * nr_throttled \d+
      * throttled_time \d+
-     * 
- *

+ *

* where {@code nr_periods} is the number of period intervals * as specified by {@code cpu.cfs_period_us} that have elapsed, * {@code nr_throttled} is the number of times tasks in the given From 44c3b04bef55ed4a51d10f907be9a5aae20d1fa6 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Tue, 25 Oct 2016 10:56:30 -0400 Subject: [PATCH 08/19] Convert more docs to // CONSOLE Converts docs for `_cat/segments`, `_cat/plugins` and `_cat/repositories` from `curl` to `// CONSOLE` so they are tested as part of the build and are cleaner to use in Console. They should work fine with `curl` with the `COPY AS CURL` link. Also swaps the `source` type of the response from `js` to `txt` because that is more correct. The syntax highlighter doesn't care. It looks at the text to figure out the language. So it looks a little funny for `_cat` responses regardless. Relates to #18160 --- docs/build.gradle | 3 -- docs/reference/cat/alias.asciidoc | 2 +- docs/reference/cat/allocation.asciidoc | 2 +- docs/reference/cat/count.asciidoc | 4 +-- docs/reference/cat/fielddata.asciidoc | 6 ++-- docs/reference/cat/health.asciidoc | 4 +-- docs/reference/cat/indices.asciidoc | 6 ++-- docs/reference/cat/master.asciidoc | 2 +- docs/reference/cat/nodeattrs.asciidoc | 2 +- docs/reference/cat/nodes.asciidoc | 2 +- docs/reference/cat/pending_tasks.asciidoc | 2 +- docs/reference/cat/plugins.asciidoc | 34 +++++++++++++++++++---- docs/reference/cat/repositories.asciidoc | 16 +++++++++-- docs/reference/cat/segments.asciidoc | 24 ++++++++-------- 14 files changed, 70 insertions(+), 39 deletions(-) diff --git a/docs/build.gradle b/docs/build.gradle index 19b7be6cead..35ced85b0c7 100644 --- a/docs/build.gradle +++ b/docs/build.gradle @@ -93,10 +93,7 @@ buildRestTests.expectedUnconvertedCandidates = [ 'reference/analysis/tokenfilters/stop-tokenfilter.asciidoc', 'reference/analysis/tokenfilters/synonym-tokenfilter.asciidoc', 'reference/analysis/tokenfilters/word-delimiter-tokenfilter.asciidoc', - 'reference/cat/plugins.asciidoc', 'reference/cat/recovery.asciidoc', - 'reference/cat/repositories.asciidoc', - 'reference/cat/segments.asciidoc', 'reference/cat/shards.asciidoc', 'reference/cat/snapshots.asciidoc', 'reference/cat/templates.asciidoc', diff --git a/docs/reference/cat/alias.asciidoc b/docs/reference/cat/alias.asciidoc index f86f02fc034..4c176499a2f 100644 --- a/docs/reference/cat/alias.asciidoc +++ b/docs/reference/cat/alias.asciidoc @@ -41,7 +41,7 @@ GET /_cat/aliases?v Might respond with: -[source,js] +[source,txt] -------------------------------------------------- alias index filter routing.index routing.search alias1 test1 - - - diff --git a/docs/reference/cat/allocation.asciidoc b/docs/reference/cat/allocation.asciidoc index 3826b2c1b5d..ba702080e58 100644 --- a/docs/reference/cat/allocation.asciidoc +++ b/docs/reference/cat/allocation.asciidoc @@ -13,7 +13,7 @@ GET /_cat/allocation?v Might respond with: -[source,js] +[source,txt] -------------------------------------------------- shards disk.indices disk.used disk.avail disk.total disk.percent host ip node 5 260b 47.3gb 43.4gb 100.7gb 46 127.0.0.1 127.0.0.1 CSUXak2 diff --git a/docs/reference/cat/count.asciidoc b/docs/reference/cat/count.asciidoc index 9a8c1b8c65b..28dc39adc8d 100644 --- a/docs/reference/cat/count.asciidoc +++ b/docs/reference/cat/count.asciidoc @@ -14,7 +14,7 @@ GET /_cat/count?v Looks like: -[source,js] +[source,txt] -------------------------------------------------- epoch timestamp count 1475868259 15:24:19 121 @@ -30,7 +30,7 @@ GET /_cat/count/twitter?v // CONSOLE // TEST[continued] -[source,js] +[source,txt] -------------------------------------------------- epoch timestamp count 1475868259 15:24:20 120 diff --git a/docs/reference/cat/fielddata.asciidoc b/docs/reference/cat/fielddata.asciidoc index c4dc10fbff1..d6d7d872dc4 100644 --- a/docs/reference/cat/fielddata.asciidoc +++ b/docs/reference/cat/fielddata.asciidoc @@ -47,7 +47,7 @@ GET /_cat/fielddata?v Looks like: -[source,js] +[source,txt] -------------------------------------------------- id host ip node field size Nqk-6inXQq-OxUfOUI8jNQ 127.0.0.1 127.0.0.1 Nqk-6in body 544b @@ -67,7 +67,7 @@ GET /_cat/fielddata?v&fields=body Which looks like: -[source,js] +[source,txt] -------------------------------------------------- id host ip node field size Nqk-6inXQq-OxUfOUI8jNQ 127.0.0.1 127.0.0.1 Nqk-6in body 544b @@ -86,7 +86,7 @@ GET /_cat/fielddata/body,soul?v Which produces the same output as the first snippet: -[source,js] +[source,txt] -------------------------------------------------- id host ip node field size Nqk-6inXQq-OxUfOUI8jNQ 127.0.0.1 127.0.0.1 Nqk-6in body 544b diff --git a/docs/reference/cat/health.asciidoc b/docs/reference/cat/health.asciidoc index 662e8c84835..cca24c66a36 100644 --- a/docs/reference/cat/health.asciidoc +++ b/docs/reference/cat/health.asciidoc @@ -11,7 +11,7 @@ GET /_cat/health?v // CONSOLE // TEST[s/^/PUT twitter\n{"settings":{"number_of_replicas": 0}}\n/] -[source,js] +[source,txt] -------------------------------------------------- epoch timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent 1475871424 16:17:04 elasticsearch green 1 1 5 5 0 0 0 0 - 100.0% @@ -29,7 +29,7 @@ GET /_cat/health?v&ts=0 which looks like: -[source,js] +[source,txt] -------------------------------------------------- cluster status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent elasticsearch green 1 1 5 5 0 0 0 0 - 100.0% diff --git a/docs/reference/cat/indices.asciidoc b/docs/reference/cat/indices.asciidoc index 11dfb3c7c6a..ee8a58f6a95 100644 --- a/docs/reference/cat/indices.asciidoc +++ b/docs/reference/cat/indices.asciidoc @@ -14,7 +14,7 @@ GET /_cat/indices/twi*?v&s=index Might respond with: -[source,js] +[source,txt] -------------------------------------------------- health status index uuid pri rep docs.count docs.deleted store.size pri.store.size yellow open twitter u8FNjxh8Rfy_awN11oDKYQ 1 1 1200 0 88.1kb 88.1kb @@ -51,7 +51,7 @@ GET /_cat/indices?v&health=yellow Which looks like: -[source,js] +[source,txt] -------------------------------------------------- health status index uuid pri rep docs.count docs.deleted store.size pri.store.size yellow open twitter u8FNjxh8Rfy_awN11oDKYQ 1 1 1200 0 88.1kb 88.1kb @@ -71,7 +71,7 @@ GET /_cat/indices?v&s=store.size:desc Which looks like: -[source,js] +[source,txt] -------------------------------------------------- health status index uuid pri rep docs.count docs.deleted store.size pri.store.size yellow open twitter u8FNjxh8Rfy_awN11oDKYQ 1 1 1200 0 88.1kb 88.1kb diff --git a/docs/reference/cat/master.asciidoc b/docs/reference/cat/master.asciidoc index cf203a3eee0..dfa10d6e3a4 100644 --- a/docs/reference/cat/master.asciidoc +++ b/docs/reference/cat/master.asciidoc @@ -12,7 +12,7 @@ GET /_cat/master?v might respond: -[source,js] +[source,txt] -------------------------------------------------- id host ip node YzWoH_2BT-6UjVGDyPdqYg 127.0.0.1 127.0.0.1 YzWoH_2 diff --git a/docs/reference/cat/nodeattrs.asciidoc b/docs/reference/cat/nodeattrs.asciidoc index a7cbecb50db..18feeba8d03 100644 --- a/docs/reference/cat/nodeattrs.asciidoc +++ b/docs/reference/cat/nodeattrs.asciidoc @@ -12,7 +12,7 @@ GET /_cat/nodeattrs?v Could look like: -[source,js] +[source,txt] -------------------------------------------------- node host ip attr value EK_AsJb 127.0.0.1 127.0.0.1 testattr test diff --git a/docs/reference/cat/nodes.asciidoc b/docs/reference/cat/nodes.asciidoc index 8885e490fca..2d9312a7849 100644 --- a/docs/reference/cat/nodes.asciidoc +++ b/docs/reference/cat/nodes.asciidoc @@ -11,7 +11,7 @@ GET /_cat/nodes?v Might look like: -[source,js] +[source,txt] -------------------------------------------------- ip heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name 127.0.0.1 65 99 42 3.07 mdi * mJw06l1 diff --git a/docs/reference/cat/pending_tasks.asciidoc b/docs/reference/cat/pending_tasks.asciidoc index fc0c20d5e13..d5216c1eb00 100644 --- a/docs/reference/cat/pending_tasks.asciidoc +++ b/docs/reference/cat/pending_tasks.asciidoc @@ -13,7 +13,7 @@ GET /_cat/pending_tasks?v Might look like: -[source,js] +[source,txt] -------------------------------------------------- insertOrder timeInQueue priority source 1685 855ms HIGH update-mapping [foo][t] diff --git a/docs/reference/cat/plugins.asciidoc b/docs/reference/cat/plugins.asciidoc index a1d0dc88702..b2a193dfa8c 100644 --- a/docs/reference/cat/plugins.asciidoc +++ b/docs/reference/cat/plugins.asciidoc @@ -3,12 +3,36 @@ The `plugins` command provides a view per node of running plugins. This information *spans nodes*. -[source,sh] +[source,js] ------------------------------------------------------------------------------ -% curl 'localhost:9200/_cat/plugins?v' -name component version description -I8hydUG discovery-gce 5.0.0 The Google Compute Engine (GCE) Discovery plugin allows to use GCE API for the unicast discovery mechanism. -I8hydUG lang-javascript 5.0.0 The JavaScript language plugin allows to have javascript as the language of scripts to execute. +GET /_cat/plugins?v&s=component&h=name,component,version,description +------------------------------------------------------------------------------ +// CONSOLE + +Might look like: + +["source","txt",subs="attributes,callouts"] +------------------------------------------------------------------------------ +name component version description +U7321H6 analysis-icu {version} The ICU Analysis plugin integrates Lucene ICU module into elasticsearch, adding ICU relates analysis components. +U7321H6 analysis-kuromoji {version} The Japanese (kuromoji) Analysis plugin integrates Lucene kuromoji analysis module into elasticsearch. +U7321H6 analysis-phonetic {version} The Phonetic Analysis plugin integrates phonetic token filter analysis with elasticsearch. +U7321H6 analysis-smartcn {version} Smart Chinese Analysis plugin integrates Lucene Smart Chinese analysis module into elasticsearch. +U7321H6 analysis-stempel {version} The Stempel (Polish) Analysis plugin integrates Lucene stempel (polish) analysis module into elasticsearch. +U7321H6 discovery-azure-classic {version} The Azure Classic Discovery plugin allows to use Azure Classic API for the unicast discovery mechanism +U7321H6 discovery-ec2 {version} The EC2 discovery plugin allows to use AWS API for the unicast discovery mechanism. +U7321H6 discovery-file {version} Discovery file plugin enables unicast discovery from hosts stored in a file. +U7321H6 discovery-gce {version} The Google Compute Engine (GCE) Discovery plugin allows to use GCE API for the unicast discovery mechanism. +U7321H6 ingest-attachment {version} Ingest processor that uses Apache Tika to extract contents +U7321H6 ingest-geoip {version} Ingest processor that uses looksup geo data based on ip adresses using the Maxmind geo database +U7321H6 ingest-user-agent {version} Ingest processor that extracts information from a user agent +U7321H6 jvm-example {version} Demonstrates all the pluggable Java entry points in Elasticsearch +U7321H6 lang-javascript {version} The JavaScript language plugin allows to have javascript as the language of scripts to execute. +U7321H6 lang-python {version} The Python language plugin allows to have python as the language of scripts to execute. +U7321H6 mapper-murmur3 {version} The Mapper Murmur3 plugin allows to compute hashes of a field's values at index-time and to store them in the index. +U7321H6 mapper-size {version} The Mapper Size plugin allows document to record their uncompressed size at index time. +U7321H6 store-smb {version} The Store SMB plugin adds support for SMB stores. ------------------------------------------------------------------------------- +// TESTRESPONSE[s/([.()])/\\$1/ s/U7321H6/.+/ _cat] We can tell quickly how many plugins per node we have and which versions. diff --git a/docs/reference/cat/repositories.asciidoc b/docs/reference/cat/repositories.asciidoc index 5fb68a8929c..8caf3c5fd6f 100644 --- a/docs/reference/cat/repositories.asciidoc +++ b/docs/reference/cat/repositories.asciidoc @@ -1,14 +1,24 @@ [[cat-repositories]] == cat repositories -The `repositories` command shows the snapshot repositories registered in the cluster. +The `repositories` command shows the snapshot repositories registered in the +cluster. For example: -[source,sh] +[source,js] +-------------------------------------------------- +GET /_cat/repositories?v +-------------------------------------------------- +// CONSOLE +// TEST[s/^/PUT \/_snapshot\/repo1\n{"type": "fs", "settings": {"location": "repo\/1"}}\n/] + +might looks like: + +[source,txt] -------------------------------------------------- -% curl 'localhost:9200/_cat/repositories?v' id type repo1 fs repo2 s3 -------------------------------------------------- +// TESTRESPONSE[s/\nrepo2 s3// _cat] We can quickly see which repositories are registered and their type. diff --git a/docs/reference/cat/segments.asciidoc b/docs/reference/cat/segments.asciidoc index 84456e3a313..d0b0e369538 100644 --- a/docs/reference/cat/segments.asciidoc +++ b/docs/reference/cat/segments.asciidoc @@ -3,24 +3,24 @@ The `segments` command provides low level information about the segments in the shards of an index. It provides information similar to the -link:indices-segments.html[_segments] endpoint. +link:indices-segments.html[_segments] endpoint. For example: -[source,sh] +[source,js] -------------------------------------------------- -% curl 'http://localhost:9200/_cat/segments?v' -index shard prirep ip segment generation docs.count [...] -test 4 p 192.168.2.105 _0 0 1 -test1 2 p 192.168.2.105 _0 0 1 -test1 3 p 192.168.2.105 _2 2 1 +GET /_cat/segments?v -------------------------------------------------- +// CONSOLE +// TEST[s/^/PUT \/test\/test\/1?refresh\n{"test":"test"}\nPUT \/test1\/test\/1?refresh\n{"test":"test"}\n/] -[source,sh] +might look like: + +["source","txt",subs="attributes,callouts"] -------------------------------------------------- -[...] docs.deleted size size.memory committed searchable version compound - 0 2.9kb 7818 false true 4.10.2 true - 0 2.9kb 7818 false true 4.10.2 true - 0 2.9kb 7818 false true 4.10.2 true +index shard prirep ip segment generation docs.count docs.deleted size size.memory committed searchable version compound +test 3 p 127.0.0.1 _0 0 1 0 3kb 2042 false true {lucene_version} true +test1 3 p 127.0.0.1 _0 0 1 0 3kb 2042 false true {lucene_version} true -------------------------------------------------- +// TESTRESPONSE[s/3kb/\\d+(\\.\\d+)?[mk]?b/ s/2042/\\d+/ _cat] The output shows information about index names and shard numbers in the first two columns. From 7945894ede0a3e95b056b9e3e6e6b8393001000f Mon Sep 17 00:00:00 2001 From: Britta Weber Date: Tue, 25 Oct 2016 18:29:23 +0200 Subject: [PATCH 09/19] Remove unused interface InitialStateDiscoveryListener (#21115) --- .../InitialStateDiscoveryListener.java | 33 ------------------- 1 file changed, 33 deletions(-) delete mode 100644 core/src/main/java/org/elasticsearch/discovery/InitialStateDiscoveryListener.java diff --git a/core/src/main/java/org/elasticsearch/discovery/InitialStateDiscoveryListener.java b/core/src/main/java/org/elasticsearch/discovery/InitialStateDiscoveryListener.java deleted file mode 100644 index 1ec55c874b4..00000000000 --- a/core/src/main/java/org/elasticsearch/discovery/InitialStateDiscoveryListener.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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.discovery; - -/** - * A listener that should be called by the {@link org.elasticsearch.discovery.Discovery} component - * when the first valid initial cluster state has been submitted and processed by the cluster service. - *

- * Note, this listener should be registered with the discovery service before it has started. - * - * - */ -public interface InitialStateDiscoveryListener { - - void initialStateProcessed(); -} From 17ad88d539ded5a935fc7c37e13a565a3b4a697c Mon Sep 17 00:00:00 2001 From: Igor Motov Date: Tue, 25 Oct 2016 12:27:33 -1000 Subject: [PATCH 10/19] Makes search action cancelable by task management API Long running searches now can be cancelled using standard task cancellation mechanism. --- .../elasticsearch/ElasticsearchException.java | 4 +- .../search/AbstractSearchAsyncAction.java | 4 +- .../SearchDfsQueryAndFetchAsyncAction.java | 8 +- .../SearchDfsQueryThenFetchAsyncAction.java | 11 +- .../SearchQueryAndFetchAsyncAction.java | 7 +- .../SearchQueryThenFetchAsyncAction.java | 9 +- .../action/search/SearchRequest.java | 7 + .../SearchScrollQueryAndFetchAsyncAction.java | 10 +- ...SearchScrollQueryThenFetchAsyncAction.java | 12 +- .../action/search/SearchScrollRequest.java | 7 + .../action/search/SearchTask.java | 34 ++ .../action/search/SearchTransportService.java | 195 +++++++----- .../action/search/TransportSearchAction.java | 24 +- .../search/TransportSearchScrollAction.java | 12 +- .../common/settings/ClusterSettings.java | 1 + .../search/DefaultSearchContext.java | 28 ++ .../elasticsearch/search/SearchService.java | 44 ++- .../elasticsearch/search/dfs/DfsPhase.java | 8 + .../dfs/DfsPhaseExecutionException.java | 6 +- .../search/fetch/FetchPhase.java | 4 + .../fetch/FetchPhaseExecutionException.java | 4 + .../search/fetch/ShardFetchRequest.java | 8 + .../internal/FilteredSearchContext.java | 21 ++ .../internal/InternalScrollSearchRequest.java | 8 + .../search/internal/SearchContext.java | 15 + .../internal/ShardSearchTransportRequest.java | 8 + .../search/profile/query/CollectorResult.java | 1 + .../search/query/CancellableCollector.java | 78 +++++ .../search/query/QueryPhase.java | 9 + .../search/query/QuerySearchRequest.java | 8 + .../tasks/TaskCancelledException.java | 38 +++ .../org/elasticsearch/tasks/TaskManager.java | 2 +- .../TaskAwareTransportRequestHandler.java | 30 ++ .../transport/TransportService.java | 23 ++ .../ExceptionSerializationTests.java | 1 + .../node/tasks/CancellableTasksTests.java | 3 +- .../action/search/SearchAsyncActionTests.java | 2 +- .../search/SearchCancellationIT.java | 297 ++++++++++++++++++ .../search/SearchCancellationTests.java | 97 ++++++ .../search/SearchServiceTests.java | 6 +- .../search/query/QueryPhaseTests.java | 4 + docs/reference/cluster/tasks.asciidoc | 1 + docs/reference/search.asciidoc | 13 + docs/reference/search/profile.asciidoc | 43 ++- .../elasticsearch/test/TestSearchContext.java | 21 ++ 45 files changed, 1036 insertions(+), 140 deletions(-) create mode 100644 core/src/main/java/org/elasticsearch/action/search/SearchTask.java create mode 100644 core/src/main/java/org/elasticsearch/search/query/CancellableCollector.java create mode 100644 core/src/main/java/org/elasticsearch/tasks/TaskCancelledException.java create mode 100644 core/src/main/java/org/elasticsearch/transport/TaskAwareTransportRequestHandler.java create mode 100644 core/src/test/java/org/elasticsearch/search/SearchCancellationIT.java create mode 100644 core/src/test/java/org/elasticsearch/search/SearchCancellationTests.java diff --git a/core/src/main/java/org/elasticsearch/ElasticsearchException.java b/core/src/main/java/org/elasticsearch/ElasticsearchException.java index 63161a0a187..9fd978feb4f 100644 --- a/core/src/main/java/org/elasticsearch/ElasticsearchException.java +++ b/core/src/main/java/org/elasticsearch/ElasticsearchException.java @@ -693,7 +693,9 @@ public class ElasticsearchException extends RuntimeException implements ToXConte ShardStateAction.NoLongerPrimaryShardException::new, 142), SCRIPT_EXCEPTION(org.elasticsearch.script.ScriptException.class, org.elasticsearch.script.ScriptException::new, 143), NOT_MASTER_EXCEPTION(org.elasticsearch.cluster.NotMasterException.class, org.elasticsearch.cluster.NotMasterException::new, 144), - STATUS_EXCEPTION(org.elasticsearch.ElasticsearchStatusException.class, org.elasticsearch.ElasticsearchStatusException::new, 145); + STATUS_EXCEPTION(org.elasticsearch.ElasticsearchStatusException.class, org.elasticsearch.ElasticsearchStatusException::new, 145), + TASK_CANCELLED_EXCEPTION(org.elasticsearch.tasks.TaskCancelledException.class, + org.elasticsearch.tasks.TaskCancelledException::new, 146); final Class exceptionClass; final FunctionThatThrowsIOException constructor; diff --git a/core/src/main/java/org/elasticsearch/action/search/AbstractSearchAsyncAction.java b/core/src/main/java/org/elasticsearch/action/search/AbstractSearchAsyncAction.java index bf6d34c93fb..c973804a39d 100644 --- a/core/src/main/java/org/elasticsearch/action/search/AbstractSearchAsyncAction.java +++ b/core/src/main/java/org/elasticsearch/action/search/AbstractSearchAsyncAction.java @@ -59,6 +59,7 @@ abstract class AbstractSearchAsyncAction protected final SearchRequest request; /** Used by subclasses to resolve node ids to DiscoveryNodes. **/ protected final Function nodeIdToDiscoveryNode; + protected final SearchTask task; protected final int expectedSuccessfulOps; private final int expectedTotalOps; protected final AtomicInteger successfulOps = new AtomicInteger(); @@ -74,12 +75,13 @@ abstract class AbstractSearchAsyncAction Function nodeIdToDiscoveryNode, Map aliasFilter, Executor executor, SearchRequest request, ActionListener listener, GroupShardsIterator shardsIts, long startTime, - long clusterStateVersion) { + long clusterStateVersion, SearchTask task) { super(startTime); this.logger = logger; this.searchTransportService = searchTransportService; this.executor = executor; this.request = request; + this.task = task; this.listener = listener; this.nodeIdToDiscoveryNode = nodeIdToDiscoveryNode; this.clusterStateVersion = clusterStateVersion; diff --git a/core/src/main/java/org/elasticsearch/action/search/SearchDfsQueryAndFetchAsyncAction.java b/core/src/main/java/org/elasticsearch/action/search/SearchDfsQueryAndFetchAsyncAction.java index 24b1033ca5f..54117495cba 100644 --- a/core/src/main/java/org/elasticsearch/action/search/SearchDfsQueryAndFetchAsyncAction.java +++ b/core/src/main/java/org/elasticsearch/action/search/SearchDfsQueryAndFetchAsyncAction.java @@ -49,9 +49,9 @@ class SearchDfsQueryAndFetchAsyncAction extends AbstractSearchAsyncAction nodeIdToDiscoveryNode, Map aliasFilter, SearchPhaseController searchPhaseController, Executor executor, SearchRequest request, ActionListener listener, - GroupShardsIterator shardsIts, long startTime, long clusterStateVersion) { + GroupShardsIterator shardsIts, long startTime, long clusterStateVersion, SearchTask task) { super(logger, searchTransportService, nodeIdToDiscoveryNode, aliasFilter, executor, - request, listener, shardsIts, startTime, clusterStateVersion); + request, listener, shardsIts, startTime, clusterStateVersion, task); this.searchPhaseController = searchPhaseController; queryFetchResults = new AtomicArray<>(firstResults.length()); } @@ -64,7 +64,7 @@ class SearchDfsQueryAndFetchAsyncAction extends AbstractSearchAsyncAction listener) { - searchTransportService.sendExecuteDfs(node, request, listener); + searchTransportService.sendExecuteDfs(node, request, task, listener); } @Override @@ -82,7 +82,7 @@ class SearchDfsQueryAndFetchAsyncAction extends AbstractSearchAsyncAction() { + searchTransportService.sendExecuteFetch(node, querySearchRequest, task, new ActionListener() { @Override public void onResponse(QueryFetchSearchResult result) { result.shardTarget(dfsResult.shardTarget()); diff --git a/core/src/main/java/org/elasticsearch/action/search/SearchDfsQueryThenFetchAsyncAction.java b/core/src/main/java/org/elasticsearch/action/search/SearchDfsQueryThenFetchAsyncAction.java index 1af6d4da4d1..3f8b20bc1fa 100644 --- a/core/src/main/java/org/elasticsearch/action/search/SearchDfsQueryThenFetchAsyncAction.java +++ b/core/src/main/java/org/elasticsearch/action/search/SearchDfsQueryThenFetchAsyncAction.java @@ -57,9 +57,10 @@ class SearchDfsQueryThenFetchAsyncAction extends AbstractSearchAsyncAction nodeIdToDiscoveryNode, Map aliasFilter, SearchPhaseController searchPhaseController, Executor executor, SearchRequest request, ActionListener listener, - GroupShardsIterator shardsIts, long startTime, long clusterStateVersion) { + GroupShardsIterator shardsIts, long startTime, long clusterStateVersion, + SearchTask task) { super(logger, searchTransportService, nodeIdToDiscoveryNode, aliasFilter, executor, - request, listener, shardsIts, startTime, clusterStateVersion); + request, listener, shardsIts, startTime, clusterStateVersion, task); this.searchPhaseController = searchPhaseController; queryResults = new AtomicArray<>(firstResults.length()); fetchResults = new AtomicArray<>(firstResults.length()); @@ -74,7 +75,7 @@ class SearchDfsQueryThenFetchAsyncAction extends AbstractSearchAsyncAction listener) { - searchTransportService.sendExecuteDfs(node, request, listener); + searchTransportService.sendExecuteDfs(node, request, task, listener); } @Override @@ -91,7 +92,7 @@ class SearchDfsQueryThenFetchAsyncAction extends AbstractSearchAsyncAction() { + searchTransportService.sendExecuteQuery(node, querySearchRequest, task, new ActionListener() { @Override public void onResponse(QuerySearchResult result) { result.shardTarget(dfsResult.shardTarget()); @@ -162,7 +163,7 @@ class SearchDfsQueryThenFetchAsyncAction extends AbstractSearchAsyncAction() { + searchTransportService.sendExecuteFetch(node, fetchSearchRequest, task, new ActionListener() { @Override public void onResponse(FetchSearchResult result) { result.shardTarget(shardTarget); diff --git a/core/src/main/java/org/elasticsearch/action/search/SearchQueryAndFetchAsyncAction.java b/core/src/main/java/org/elasticsearch/action/search/SearchQueryAndFetchAsyncAction.java index 4e8c3847ffc..25e7e14bb87 100644 --- a/core/src/main/java/org/elasticsearch/action/search/SearchQueryAndFetchAsyncAction.java +++ b/core/src/main/java/org/elasticsearch/action/search/SearchQueryAndFetchAsyncAction.java @@ -43,9 +43,10 @@ class SearchQueryAndFetchAsyncAction extends AbstractSearchAsyncAction aliasFilter, SearchPhaseController searchPhaseController, Executor executor, SearchRequest request, ActionListener listener, - GroupShardsIterator shardsIts, long startTime, long clusterStateVersion) { + GroupShardsIterator shardsIts, long startTime, long clusterStateVersion, + SearchTask task) { super(logger, searchTransportService, nodeIdToDiscoveryNode, aliasFilter, executor, - request, listener, shardsIts, startTime, clusterStateVersion); + request, listener, shardsIts, startTime, clusterStateVersion, task); this.searchPhaseController = searchPhaseController; } @@ -58,7 +59,7 @@ class SearchQueryAndFetchAsyncAction extends AbstractSearchAsyncAction listener) { - searchTransportService.sendExecuteFetch(node, request, listener); + searchTransportService.sendExecuteFetch(node, request, task, listener); } @Override diff --git a/core/src/main/java/org/elasticsearch/action/search/SearchQueryThenFetchAsyncAction.java b/core/src/main/java/org/elasticsearch/action/search/SearchQueryThenFetchAsyncAction.java index 0bcae7502ee..23b744e5de1 100644 --- a/core/src/main/java/org/elasticsearch/action/search/SearchQueryThenFetchAsyncAction.java +++ b/core/src/main/java/org/elasticsearch/action/search/SearchQueryThenFetchAsyncAction.java @@ -54,9 +54,10 @@ class SearchQueryThenFetchAsyncAction extends AbstractSearchAsyncAction aliasFilter, SearchPhaseController searchPhaseController, Executor executor, SearchRequest request, ActionListener listener, - GroupShardsIterator shardsIts, long startTime, long clusterStateVersion) { + GroupShardsIterator shardsIts, long startTime, long clusterStateVersion, + SearchTask task) { super(logger, searchTransportService, nodeIdToDiscoveryNode, aliasFilter, executor, request, listener, - shardsIts, startTime, clusterStateVersion); + shardsIts, startTime, clusterStateVersion, task); this.searchPhaseController = searchPhaseController; fetchResults = new AtomicArray<>(firstResults.length()); docIdsToLoad = new AtomicArray<>(firstResults.length()); @@ -70,7 +71,7 @@ class SearchQueryThenFetchAsyncAction extends AbstractSearchAsyncAction listener) { - searchTransportService.sendExecuteQuery(node, request, listener); + searchTransportService.sendExecuteQuery(node, request, task, listener); } @Override @@ -97,7 +98,7 @@ class SearchQueryThenFetchAsyncAction extends AbstractSearchAsyncAction() { + searchTransportService.sendExecuteFetch(node, fetchSearchRequest, task, new ActionListener() { @Override public void onResponse(FetchSearchResult result) { result.shardTarget(shardTarget); diff --git a/core/src/main/java/org/elasticsearch/action/search/SearchRequest.java b/core/src/main/java/org/elasticsearch/action/search/SearchRequest.java index a1b1a02a97e..de27805b139 100644 --- a/core/src/main/java/org/elasticsearch/action/search/SearchRequest.java +++ b/core/src/main/java/org/elasticsearch/action/search/SearchRequest.java @@ -31,6 +31,8 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.search.Scroll; import org.elasticsearch.search.builder.SearchSourceBuilder; +import org.elasticsearch.tasks.Task; +import org.elasticsearch.tasks.TaskId; import java.io.IOException; import java.util.Arrays; @@ -275,6 +277,11 @@ public final class SearchRequest extends ActionRequest implements return source != null && source.isSuggestOnly(); } + @Override + public Task createTask(long id, String type, String action, TaskId parentTaskId) { + return new SearchTask(id, type, action, getDescription(), parentTaskId); + } + @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); diff --git a/core/src/main/java/org/elasticsearch/action/search/SearchScrollQueryAndFetchAsyncAction.java b/core/src/main/java/org/elasticsearch/action/search/SearchScrollQueryAndFetchAsyncAction.java index 2bdf7dc30f9..bf53fc719c6 100644 --- a/core/src/main/java/org/elasticsearch/action/search/SearchScrollQueryAndFetchAsyncAction.java +++ b/core/src/main/java/org/elasticsearch/action/search/SearchScrollQueryAndFetchAsyncAction.java @@ -44,6 +44,7 @@ class SearchScrollQueryAndFetchAsyncAction extends AbstractAsyncAction { private final SearchPhaseController searchPhaseController; private final SearchTransportService searchTransportService; private final SearchScrollRequest request; + private final SearchTask task; private final ActionListener listener; private final ParsedScrollId scrollId; private final DiscoveryNodes nodes; @@ -52,13 +53,14 @@ class SearchScrollQueryAndFetchAsyncAction extends AbstractAsyncAction { private final AtomicInteger successfulOps; private final AtomicInteger counter; - SearchScrollQueryAndFetchAsyncAction(Logger logger, ClusterService clusterService, - SearchTransportService searchTransportService, SearchPhaseController searchPhaseController, - SearchScrollRequest request, ParsedScrollId scrollId, ActionListener listener) { + SearchScrollQueryAndFetchAsyncAction(Logger logger, ClusterService clusterService, SearchTransportService searchTransportService, + SearchPhaseController searchPhaseController, SearchScrollRequest request, SearchTask task, + ParsedScrollId scrollId, ActionListener listener) { this.logger = logger; this.searchPhaseController = searchPhaseController; this.searchTransportService = searchTransportService; this.request = request; + this.task = task; this.listener = listener; this.scrollId = scrollId; this.nodes = clusterService.state().nodes(); @@ -128,7 +130,7 @@ class SearchScrollQueryAndFetchAsyncAction extends AbstractAsyncAction { void executePhase(final int shardIndex, DiscoveryNode node, final long searchId) { InternalScrollSearchRequest internalRequest = internalScrollSearchRequest(searchId, request); - searchTransportService.sendExecuteFetch(node, internalRequest, new ActionListener() { + searchTransportService.sendExecuteFetch(node, internalRequest, task, new ActionListener() { @Override public void onResponse(ScrollQueryFetchSearchResult result) { queryFetchResults.set(shardIndex, result.result()); diff --git a/core/src/main/java/org/elasticsearch/action/search/SearchScrollQueryThenFetchAsyncAction.java b/core/src/main/java/org/elasticsearch/action/search/SearchScrollQueryThenFetchAsyncAction.java index 4024d3b5f39..851e3343bc2 100644 --- a/core/src/main/java/org/elasticsearch/action/search/SearchScrollQueryThenFetchAsyncAction.java +++ b/core/src/main/java/org/elasticsearch/action/search/SearchScrollQueryThenFetchAsyncAction.java @@ -44,6 +44,7 @@ import static org.elasticsearch.action.search.TransportSearchHelper.internalScro class SearchScrollQueryThenFetchAsyncAction extends AbstractAsyncAction { private final Logger logger; + private final SearchTask task; private final SearchTransportService searchTransportService; private final SearchPhaseController searchPhaseController; private final SearchScrollRequest request; @@ -56,13 +57,14 @@ class SearchScrollQueryThenFetchAsyncAction extends AbstractAsyncAction { private volatile ScoreDoc[] sortedShardDocs; private final AtomicInteger successfulOps; - SearchScrollQueryThenFetchAsyncAction(Logger logger, ClusterService clusterService, - SearchTransportService searchTransportService, SearchPhaseController searchPhaseController, - SearchScrollRequest request, ParsedScrollId scrollId, ActionListener listener) { + SearchScrollQueryThenFetchAsyncAction(Logger logger, ClusterService clusterService, SearchTransportService searchTransportService, + SearchPhaseController searchPhaseController, SearchScrollRequest request, SearchTask task, + ParsedScrollId scrollId, ActionListener listener) { this.logger = logger; this.searchTransportService = searchTransportService; this.searchPhaseController = searchPhaseController; this.request = request; + this.task = task; this.listener = listener; this.scrollId = scrollId; this.nodes = clusterService.state().nodes(); @@ -124,7 +126,7 @@ class SearchScrollQueryThenFetchAsyncAction extends AbstractAsyncAction { private void executeQueryPhase(final int shardIndex, final AtomicInteger counter, DiscoveryNode node, final long searchId) { InternalScrollSearchRequest internalRequest = internalScrollSearchRequest(searchId, request); - searchTransportService.sendExecuteQuery(node, internalRequest, new ActionListener() { + searchTransportService.sendExecuteQuery(node, internalRequest, task, new ActionListener() { @Override public void onResponse(ScrollQuerySearchResult result) { queryResults.set(shardIndex, result.queryResult()); @@ -184,7 +186,7 @@ class SearchScrollQueryThenFetchAsyncAction extends AbstractAsyncAction { ScoreDoc lastEmittedDoc = lastEmittedDocPerShard[entry.index]; ShardFetchRequest shardFetchRequest = new ShardFetchRequest(querySearchResult.id(), docIds, lastEmittedDoc); DiscoveryNode node = nodes.get(querySearchResult.shardTarget().nodeId()); - searchTransportService.sendExecuteFetchScroll(node, shardFetchRequest, new ActionListener() { + searchTransportService.sendExecuteFetchScroll(node, shardFetchRequest, task, new ActionListener() { @Override public void onResponse(FetchSearchResult result) { result.shardTarget(querySearchResult.shardTarget()); diff --git a/core/src/main/java/org/elasticsearch/action/search/SearchScrollRequest.java b/core/src/main/java/org/elasticsearch/action/search/SearchScrollRequest.java index eff033a7600..8a171e24a1e 100644 --- a/core/src/main/java/org/elasticsearch/action/search/SearchScrollRequest.java +++ b/core/src/main/java/org/elasticsearch/action/search/SearchScrollRequest.java @@ -25,6 +25,8 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.search.Scroll; +import org.elasticsearch.tasks.Task; +import org.elasticsearch.tasks.TaskId; import java.io.IOException; import java.util.Objects; @@ -107,6 +109,11 @@ public class SearchScrollRequest extends ActionRequest { out.writeOptionalWriteable(scroll); } + @Override + public Task createTask(long id, String type, String action, TaskId parentTaskId) { + return new SearchTask(id, type, action, getDescription(), parentTaskId); + } + @Override public boolean equals(Object o) { if (this == o) { diff --git a/core/src/main/java/org/elasticsearch/action/search/SearchTask.java b/core/src/main/java/org/elasticsearch/action/search/SearchTask.java new file mode 100644 index 00000000000..24f94a43319 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/action/search/SearchTask.java @@ -0,0 +1,34 @@ +/* + * 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.action.search; + +import org.elasticsearch.tasks.CancellableTask; +import org.elasticsearch.tasks.TaskId; + +/** + * Task storing information about a currently running search request. + */ +public class SearchTask extends CancellableTask { + + public SearchTask(long id, String type, String action, String description, TaskId parentTaskId) { + super(id, type, action, description, parentTaskId); + } + +} diff --git a/core/src/main/java/org/elasticsearch/action/search/SearchTransportService.java b/core/src/main/java/org/elasticsearch/action/search/SearchTransportService.java index 0451a8920eb..9b5d180ce10 100644 --- a/core/src/main/java/org/elasticsearch/action/search/SearchTransportService.java +++ b/core/src/main/java/org/elasticsearch/action/search/SearchTransportService.java @@ -23,6 +23,8 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListenerResponseHandler; import org.elasticsearch.action.IndicesRequest; import org.elasticsearch.action.OriginalIndices; +import org.elasticsearch.action.search.SearchRequest; +import org.elasticsearch.action.search.SearchTask; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.component.AbstractComponent; @@ -42,7 +44,10 @@ import org.elasticsearch.search.query.QuerySearchRequest; import org.elasticsearch.search.query.QuerySearchResult; import org.elasticsearch.search.query.QuerySearchResultProvider; import org.elasticsearch.search.query.ScrollQuerySearchResult; +import org.elasticsearch.tasks.Task; import org.elasticsearch.threadpool.ThreadPool; +import org.elasticsearch.transport.TaskAwareTransportRequestHandler; +import org.elasticsearch.transport.TransportChannel; import org.elasticsearch.transport.TransportRequest; import org.elasticsearch.transport.TransportResponse; import org.elasticsearch.transport.TransportService; @@ -77,22 +82,22 @@ public class SearchTransportService extends AbstractComponent { public void sendFreeContext(DiscoveryNode node, final long contextId, SearchRequest request) { transportService.sendRequest(node, FREE_CONTEXT_ACTION_NAME, new SearchFreeContextRequest(request, contextId), - new ActionListenerResponseHandler<>(new ActionListener() { - @Override - public void onResponse(SearchFreeContextResponse response) { - // no need to respond if it was freed or not - } + new ActionListenerResponseHandler<>(new ActionListener() { + @Override + public void onResponse(SearchFreeContextResponse response) { + // no need to respond if it was freed or not + } - @Override - public void onFailure(Exception e) { + @Override + public void onFailure(Exception e) { - } - }, SearchFreeContextResponse::new)); + } + }, SearchFreeContextResponse::new)); } public void sendFreeContext(DiscoveryNode node, long contextId, final ActionListener listener) { transportService.sendRequest(node, FREE_CONTEXT_SCROLL_ACTION_NAME, new ScrollFreeContextRequest(contextId), - new ActionListenerResponseHandler<>(listener, SearchFreeContextResponse::new)); + new ActionListenerResponseHandler<>(listener, SearchFreeContextResponse::new)); } public void sendClearAllScrollContexts(DiscoveryNode node, final ActionListener listener) { @@ -100,59 +105,62 @@ public class SearchTransportService extends AbstractComponent { new ActionListenerResponseHandler<>(listener, () -> TransportResponse.Empty.INSTANCE)); } - public void sendExecuteDfs(DiscoveryNode node, final ShardSearchTransportRequest request, + public void sendExecuteDfs(DiscoveryNode node, final ShardSearchTransportRequest request, SearchTask task, final ActionListener listener) { - transportService.sendRequest(node, DFS_ACTION_NAME, request, new ActionListenerResponseHandler<>(listener, DfsSearchResult::new)); + transportService.sendChildRequest(node, DFS_ACTION_NAME, request, task, + new ActionListenerResponseHandler<>(listener, DfsSearchResult::new)); } - public void sendExecuteQuery(DiscoveryNode node, final ShardSearchTransportRequest request, + public void sendExecuteQuery(DiscoveryNode node, final ShardSearchTransportRequest request, SearchTask task, final ActionListener listener) { - transportService.sendRequest(node, QUERY_ACTION_NAME, request, - new ActionListenerResponseHandler<>(listener, QuerySearchResult::new)); - } - - public void sendExecuteQuery(DiscoveryNode node, final QuerySearchRequest request, final ActionListener listener) { - transportService.sendRequest(node, QUERY_ID_ACTION_NAME, request, + transportService.sendChildRequest(node, QUERY_ACTION_NAME, request, task, new ActionListenerResponseHandler<>(listener, QuerySearchResult::new)); } - public void sendExecuteQuery(DiscoveryNode node, final InternalScrollSearchRequest request, + public void sendExecuteQuery(DiscoveryNode node, final QuerySearchRequest request, SearchTask task, + final ActionListener listener) { + transportService.sendChildRequest(node, QUERY_ID_ACTION_NAME, request, task, + new ActionListenerResponseHandler<>(listener, QuerySearchResult::new)); + } + + public void sendExecuteQuery(DiscoveryNode node, final InternalScrollSearchRequest request, SearchTask task, final ActionListener listener) { - transportService.sendRequest(node, QUERY_SCROLL_ACTION_NAME, request, - new ActionListenerResponseHandler<>(listener, ScrollQuerySearchResult::new)); + transportService.sendChildRequest(node, QUERY_SCROLL_ACTION_NAME, request, task, + new ActionListenerResponseHandler<>(listener, ScrollQuerySearchResult::new)); } - public void sendExecuteFetch(DiscoveryNode node, final ShardSearchTransportRequest request, + public void sendExecuteFetch(DiscoveryNode node, final ShardSearchTransportRequest request, SearchTask task, final ActionListener listener) { - transportService.sendRequest(node, QUERY_FETCH_ACTION_NAME, request, - new ActionListenerResponseHandler<>(listener, QueryFetchSearchResult::new)); + transportService.sendChildRequest(node, QUERY_FETCH_ACTION_NAME, request, task, + new ActionListenerResponseHandler<>(listener, QueryFetchSearchResult::new)); } - public void sendExecuteFetch(DiscoveryNode node, final QuerySearchRequest request, + public void sendExecuteFetch(DiscoveryNode node, final QuerySearchRequest request, SearchTask task, final ActionListener listener) { - transportService.sendRequest(node, QUERY_QUERY_FETCH_ACTION_NAME, request, - new ActionListenerResponseHandler<>(listener, QueryFetchSearchResult::new)); + transportService.sendChildRequest(node, QUERY_QUERY_FETCH_ACTION_NAME, request, task, + new ActionListenerResponseHandler<>(listener, QueryFetchSearchResult::new)); } - public void sendExecuteFetch(DiscoveryNode node, final InternalScrollSearchRequest request, + public void sendExecuteFetch(DiscoveryNode node, final InternalScrollSearchRequest request, SearchTask task, final ActionListener listener) { - transportService.sendRequest(node, QUERY_FETCH_SCROLL_ACTION_NAME, request, - new ActionListenerResponseHandler<>(listener, ScrollQueryFetchSearchResult::new)); + transportService.sendChildRequest(node, QUERY_FETCH_SCROLL_ACTION_NAME, request, task, + new ActionListenerResponseHandler<>(listener, ScrollQueryFetchSearchResult::new)); } - public void sendExecuteFetch(DiscoveryNode node, final ShardFetchSearchRequest request, + public void sendExecuteFetch(DiscoveryNode node, final ShardFetchSearchRequest request, SearchTask task, final ActionListener listener) { - sendExecuteFetch(node, FETCH_ID_ACTION_NAME, request, listener); + sendExecuteFetch(node, FETCH_ID_ACTION_NAME, request, task, listener); } - public void sendExecuteFetchScroll(DiscoveryNode node, final ShardFetchRequest request, + public void sendExecuteFetchScroll(DiscoveryNode node, final ShardFetchRequest request, SearchTask task, final ActionListener listener) { - sendExecuteFetch(node, FETCH_ID_SCROLL_ACTION_NAME, request, listener); + sendExecuteFetch(node, FETCH_ID_SCROLL_ACTION_NAME, request, task, listener); } - private void sendExecuteFetch(DiscoveryNode node, String action, final ShardFetchRequest request, + private void sendExecuteFetch(DiscoveryNode node, String action, final ShardFetchRequest request, SearchTask task, final ActionListener listener) { - transportService.sendRequest(node, action, request, new ActionListenerResponseHandler<>(listener, FetchSearchResult::new)); + transportService.sendChildRequest(node, action, request, task, + new ActionListenerResponseHandler<>(listener, FetchSearchResult::new)); } static class ScrollFreeContextRequest extends TransportRequest { @@ -252,64 +260,103 @@ public class SearchTransportService extends AbstractComponent { public static void registerRequestHandler(TransportService transportService, SearchService searchService) { transportService.registerRequestHandler(FREE_CONTEXT_SCROLL_ACTION_NAME, ScrollFreeContextRequest::new, ThreadPool.Names.SAME, - ((request, channel) -> { - boolean freed = searchService.freeContext(request.id()); - channel.sendResponse(new SearchFreeContextResponse(freed)); - })); + new TaskAwareTransportRequestHandler() { + @Override + public void messageReceived(ScrollFreeContextRequest request, TransportChannel channel, Task task) throws Exception { + boolean freed = searchService.freeContext(request.id()); + channel.sendResponse(new SearchFreeContextResponse(freed)); + } + }); transportService.registerRequestHandler(FREE_CONTEXT_ACTION_NAME, SearchFreeContextRequest::new, ThreadPool.Names.SAME, - (request, channel) -> { - boolean freed = searchService.freeContext(request.id()); - channel.sendResponse(new SearchFreeContextResponse(freed)); + new TaskAwareTransportRequestHandler() { + @Override + public void messageReceived(SearchFreeContextRequest request, TransportChannel channel, Task task) throws Exception { + boolean freed = searchService.freeContext(request.id()); + channel.sendResponse(new SearchFreeContextResponse(freed)); + } }); transportService.registerRequestHandler(CLEAR_SCROLL_CONTEXTS_ACTION_NAME, () -> TransportRequest.Empty.INSTANCE, - ThreadPool.Names.SAME, (request, channel) -> { - searchService.freeAllScrollContexts(); - channel.sendResponse(TransportResponse.Empty.INSTANCE); + ThreadPool.Names.SAME, + new TaskAwareTransportRequestHandler() { + @Override + public void messageReceived(TransportRequest.Empty request, TransportChannel channel, Task task) throws Exception { + searchService.freeAllScrollContexts(); + channel.sendResponse(TransportResponse.Empty.INSTANCE); + } }); transportService.registerRequestHandler(DFS_ACTION_NAME, ShardSearchTransportRequest::new, ThreadPool.Names.SEARCH, - (request, channel) -> { - DfsSearchResult result = searchService.executeDfsPhase(request); - channel.sendResponse(result); + new TaskAwareTransportRequestHandler() { + @Override + public void messageReceived(ShardSearchTransportRequest request, TransportChannel channel, Task task) throws Exception { + DfsSearchResult result = searchService.executeDfsPhase(request, (SearchTask)task); + channel.sendResponse(result); + + } }); transportService.registerRequestHandler(QUERY_ACTION_NAME, ShardSearchTransportRequest::new, ThreadPool.Names.SEARCH, - (request, channel) -> { - QuerySearchResultProvider result = searchService.executeQueryPhase(request); - channel.sendResponse(result); + new TaskAwareTransportRequestHandler() { + @Override + public void messageReceived(ShardSearchTransportRequest request, TransportChannel channel, Task task) throws Exception { + QuerySearchResultProvider result = searchService.executeQueryPhase(request, (SearchTask)task); + channel.sendResponse(result); + } }); transportService.registerRequestHandler(QUERY_ID_ACTION_NAME, QuerySearchRequest::new, ThreadPool.Names.SEARCH, - (request, channel) -> { - QuerySearchResult result = searchService.executeQueryPhase(request); - channel.sendResponse(result); + new TaskAwareTransportRequestHandler() { + @Override + public void messageReceived(QuerySearchRequest request, TransportChannel channel, Task task) throws Exception { + QuerySearchResult result = searchService.executeQueryPhase(request, (SearchTask)task); + channel.sendResponse(result); + } }); transportService.registerRequestHandler(QUERY_SCROLL_ACTION_NAME, InternalScrollSearchRequest::new, ThreadPool.Names.SEARCH, - (request, channel) -> { - ScrollQuerySearchResult result = searchService.executeQueryPhase(request); - channel.sendResponse(result); + new TaskAwareTransportRequestHandler() { + @Override + public void messageReceived(InternalScrollSearchRequest request, TransportChannel channel, Task task) throws Exception { + ScrollQuerySearchResult result = searchService.executeQueryPhase(request, (SearchTask)task); + channel.sendResponse(result); + } }); transportService.registerRequestHandler(QUERY_FETCH_ACTION_NAME, ShardSearchTransportRequest::new, ThreadPool.Names.SEARCH, - (request, channel) -> { - QueryFetchSearchResult result = searchService.executeFetchPhase(request); - channel.sendResponse(result); + new TaskAwareTransportRequestHandler() { + @Override + public void messageReceived(ShardSearchTransportRequest request, TransportChannel channel, Task task) throws Exception { + QueryFetchSearchResult result = searchService.executeFetchPhase(request, (SearchTask)task); + channel.sendResponse(result); + } }); transportService.registerRequestHandler(QUERY_QUERY_FETCH_ACTION_NAME, QuerySearchRequest::new, ThreadPool.Names.SEARCH, - (request, channel) -> { - QueryFetchSearchResult result = searchService.executeFetchPhase(request); - channel.sendResponse(result); + new TaskAwareTransportRequestHandler() { + @Override + public void messageReceived(QuerySearchRequest request, TransportChannel channel, Task task) throws Exception { + QueryFetchSearchResult result = searchService.executeFetchPhase(request, (SearchTask)task); + channel.sendResponse(result); + } }); transportService.registerRequestHandler(QUERY_FETCH_SCROLL_ACTION_NAME, InternalScrollSearchRequest::new, ThreadPool.Names.SEARCH, - (request, channel) -> { - ScrollQueryFetchSearchResult result = searchService.executeFetchPhase(request); - channel.sendResponse(result); + new TaskAwareTransportRequestHandler() { + @Override + public void messageReceived(InternalScrollSearchRequest request, TransportChannel channel, Task task) throws Exception { + ScrollQueryFetchSearchResult result = searchService.executeFetchPhase(request, (SearchTask)task); + channel.sendResponse(result); + } }); transportService.registerRequestHandler(FETCH_ID_SCROLL_ACTION_NAME, ShardFetchRequest::new, ThreadPool.Names.SEARCH, - (request, channel) -> { - FetchSearchResult result = searchService.executeFetchPhase(request); - channel.sendResponse(result); + new TaskAwareTransportRequestHandler() { + @Override + public void messageReceived(ShardFetchRequest request, TransportChannel channel, Task task) throws Exception { + FetchSearchResult result = searchService.executeFetchPhase(request, (SearchTask)task); + channel.sendResponse(result); + } }); transportService.registerRequestHandler(FETCH_ID_ACTION_NAME, ShardFetchSearchRequest::new, ThreadPool.Names.SEARCH, - (request, channel) -> { - FetchSearchResult result = searchService.executeFetchPhase(request); - channel.sendResponse(result); + new TaskAwareTransportRequestHandler() { + @Override + public void messageReceived(ShardFetchSearchRequest request, TransportChannel channel, Task task) throws Exception { + FetchSearchResult result = searchService.executeFetchPhase(request, (SearchTask)task); + channel.sendResponse(result); + } }); + } } diff --git a/core/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java b/core/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java index d8caa72f612..022519d3d9d 100644 --- a/core/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java +++ b/core/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java @@ -38,6 +38,7 @@ import org.elasticsearch.indices.IndexClosedException; import org.elasticsearch.script.ScriptService; import org.elasticsearch.search.SearchService; import org.elasticsearch.search.internal.AliasFilter; +import org.elasticsearch.tasks.Task; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; @@ -88,7 +89,7 @@ public class TransportSearchAction extends HandledTransportAction listener) { + protected void doExecute(Task task, SearchRequest searchRequest, ActionListener listener) { // pure paranoia if time goes backwards we are at least positive final long startTimeInMillis = Math.max(0, System.currentTimeMillis()); ClusterState clusterState = clusterService.state(); @@ -129,12 +130,17 @@ public class TransportSearchAction extends HandledTransportAction aliasFilter, + @Override + protected final void doExecute(SearchRequest searchRequest, ActionListener listener) { + throw new UnsupportedOperationException("the task parameter is required"); + } + + private AbstractSearchAsyncAction searchAsyncAction(SearchTask task, SearchRequest searchRequest, GroupShardsIterator shardIterators, + long startTime, ClusterState state, Map aliasFilter, ActionListener listener) { final Function nodesLookup = state.nodes()::get; final long clusterStateVersion = state.version(); @@ -144,22 +150,22 @@ public class TransportSearchAction extends HandledTransportAction listener) { + protected final void doExecute(SearchScrollRequest request, ActionListener listener) { + throw new UnsupportedOperationException("the task parameter is required"); + } + @Override + protected void doExecute(Task task, SearchScrollRequest request, ActionListener listener) { try { ParsedScrollId scrollId = parseScrollId(request.scrollId()); AbstractAsyncAction action; switch (scrollId.getType()) { case QUERY_THEN_FETCH_TYPE: action = new SearchScrollQueryThenFetchAsyncAction(logger, clusterService, searchTransportService, - searchPhaseController, request, scrollId, listener); + searchPhaseController, request, (SearchTask)task, scrollId, listener); break; case QUERY_AND_FETCH_TYPE: action = new SearchScrollQueryAndFetchAsyncAction(logger, clusterService, searchTransportService, - searchPhaseController, request, scrollId, listener); + searchPhaseController, request, (SearchTask)task, scrollId, listener); break; default: throw new IllegalArgumentException("Scroll id type [" + scrollId.getType() + "] unrecognized"); diff --git a/core/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java b/core/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java index 1c6f0abcbcf..ac4f3931b78 100644 --- a/core/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java +++ b/core/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java @@ -345,6 +345,7 @@ public final class ClusterSettings extends AbstractScopedSettings { UnicastZenPing.DISCOVERY_ZEN_PING_UNICAST_CONCURRENT_CONNECTS_SETTING, SearchService.DEFAULT_KEEPALIVE_SETTING, SearchService.KEEPALIVE_INTERVAL_SETTING, + SearchService.LOW_LEVEL_CANCELLATION_SETTING, Node.WRITE_PORTS_FIELD_SETTING, Node.NODE_NAME_SETTING, Node.NODE_DATA_SETTING, diff --git a/core/src/main/java/org/elasticsearch/search/DefaultSearchContext.java b/core/src/main/java/org/elasticsearch/search/DefaultSearchContext.java index 1e36522794a..8c4981b5541 100644 --- a/core/src/main/java/org/elasticsearch/search/DefaultSearchContext.java +++ b/core/src/main/java/org/elasticsearch/search/DefaultSearchContext.java @@ -27,6 +27,7 @@ import org.apache.lucene.search.FieldDoc; import org.apache.lucene.search.Query; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.Counter; +import org.elasticsearch.action.search.SearchTask; import org.elasticsearch.action.search.SearchType; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.ParseFieldMatcher; @@ -113,8 +114,11 @@ final class DefaultSearchContext extends SearchContext { private Float minimumScore; private boolean trackScores = false; // when sorting, track scores as well... private FieldDoc searchAfter; + private boolean lowLevelCancellation; // filter for sliced scroll private SliceBuilder sliceBuilder; + private SearchTask task; + /** * The original query as sent by the user without the types and aliases @@ -571,6 +575,15 @@ final class DefaultSearchContext extends SearchContext { return this; } + @Override + public boolean lowLevelCancellation() { + return lowLevelCancellation; + } + + public void lowLevelCancellation(boolean lowLevelCancellation) { + this.lowLevelCancellation = lowLevelCancellation; + } + @Override public FieldDoc searchAfter() { return searchAfter; @@ -792,4 +805,19 @@ final class DefaultSearchContext extends SearchContext { public void setProfilers(Profilers profilers) { this.profilers = profilers; } + + @Override + public void setTask(SearchTask task) { + this.task = task; + } + + @Override + public SearchTask getTask() { + return task; + } + + @Override + public boolean isCancelled() { + return task.isCancelled(); + } } diff --git a/core/src/main/java/org/elasticsearch/search/SearchService.java b/core/src/main/java/org/elasticsearch/search/SearchService.java index c12d0ff5263..d6ef1e0c54d 100644 --- a/core/src/main/java/org/elasticsearch/search/SearchService.java +++ b/core/src/main/java/org/elasticsearch/search/SearchService.java @@ -26,6 +26,7 @@ import org.apache.lucene.util.IOUtils; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.action.search.SearchTask; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.Nullable; @@ -84,6 +85,7 @@ import org.elasticsearch.search.sort.SortAndFormats; import org.elasticsearch.search.sort.SortBuilder; import org.elasticsearch.search.suggest.Suggest; import org.elasticsearch.search.suggest.completion.CompletionSuggestion; +import org.elasticsearch.tasks.Task; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool.Cancellable; import org.elasticsearch.threadpool.ThreadPool.Names; @@ -107,6 +109,13 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv Setting.positiveTimeSetting("search.default_keep_alive", timeValueMinutes(5), Property.NodeScope); public static final Setting KEEPALIVE_INTERVAL_SETTING = Setting.positiveTimeSetting("search.keep_alive_interval", timeValueMinutes(1), Property.NodeScope); + /** + * Enables low-level, frequent search cancellation checks. Enabling low-level checks will make long running searches to react + * to the cancellation request faster. However, since it will produce more cancellation checks it might slow the search performance + * down. + */ + public static final Setting LOW_LEVEL_CANCELLATION_SETTING = + Setting.boolSetting("search.low_level_cancellation", false, Property.Dynamic, Property.NodeScope); public static final TimeValue NO_TIMEOUT = timeValueMillis(-1); public static final Setting DEFAULT_SEARCH_TIMEOUT_SETTING = @@ -133,6 +142,8 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv private volatile TimeValue defaultSearchTimeout; + private volatile boolean lowLevelCancellation; + private final Cancellable keepAliveReaper; private final AtomicLong idGenerator = new AtomicLong(); @@ -160,12 +171,19 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv defaultSearchTimeout = DEFAULT_SEARCH_TIMEOUT_SETTING.get(settings); clusterService.getClusterSettings().addSettingsUpdateConsumer(DEFAULT_SEARCH_TIMEOUT_SETTING, this::setDefaultSearchTimeout); + + lowLevelCancellation = LOW_LEVEL_CANCELLATION_SETTING.get(settings); + clusterService.getClusterSettings().addSettingsUpdateConsumer(LOW_LEVEL_CANCELLATION_SETTING, this::setLowLevelCancellation); } private void setDefaultSearchTimeout(TimeValue defaultSearchTimeout) { this.defaultSearchTimeout = defaultSearchTimeout; } + private void setLowLevelCancellation(Boolean lowLevelCancellation) { + this.lowLevelCancellation = lowLevelCancellation; + } + @Override public void afterIndexClosed(Index index, Settings indexSettings) { // once an index is closed we can just clean up all the pending search context information @@ -212,10 +230,11 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv keepAliveReaper.cancel(); } - public DfsSearchResult executeDfsPhase(ShardSearchRequest request) throws IOException { + public DfsSearchResult executeDfsPhase(ShardSearchRequest request, SearchTask task) throws IOException { final SearchContext context = createAndPutContext(request); context.incRef(); try { + context.setTask(task); contextProcessing(context); dfsPhase.execute(context); contextProcessedSuccessfully(context); @@ -242,11 +261,12 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv } } - public QuerySearchResultProvider executeQueryPhase(ShardSearchRequest request) throws IOException { + public QuerySearchResultProvider executeQueryPhase(ShardSearchRequest request, SearchTask task) throws IOException { final SearchContext context = createAndPutContext(request); final SearchOperationListener operationListener = context.indexShard().getSearchOperationListener(); context.incRef(); try { + context.setTask(task); operationListener.onPreQueryPhase(context); long time = System.nanoTime(); contextProcessing(context); @@ -276,11 +296,12 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv } } - public ScrollQuerySearchResult executeQueryPhase(InternalScrollSearchRequest request) { + public ScrollQuerySearchResult executeQueryPhase(InternalScrollSearchRequest request, SearchTask task) { final SearchContext context = findContext(request.id()); SearchOperationListener operationListener = context.indexShard().getSearchOperationListener(); context.incRef(); try { + context.setTask(task); operationListener.onPreQueryPhase(context); long time = System.nanoTime(); contextProcessing(context); @@ -299,8 +320,9 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv } } - public QuerySearchResult executeQueryPhase(QuerySearchRequest request) { + public QuerySearchResult executeQueryPhase(QuerySearchRequest request, SearchTask task) { final SearchContext context = findContext(request.id()); + context.setTask(task); IndexShard indexShard = context.indexShard(); SearchOperationListener operationListener = indexShard.getSearchOperationListener(); context.incRef(); @@ -339,11 +361,12 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv } } - public QueryFetchSearchResult executeFetchPhase(ShardSearchRequest request) throws IOException { + public QueryFetchSearchResult executeFetchPhase(ShardSearchRequest request, SearchTask task) throws IOException { final SearchContext context = createAndPutContext(request); context.incRef(); try { contextProcessing(context); + context.setTask(task); SearchOperationListener operationListener = context.indexShard().getSearchOperationListener(); operationListener.onPreQueryPhase(context); long time = System.nanoTime(); @@ -379,10 +402,11 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv } } - public QueryFetchSearchResult executeFetchPhase(QuerySearchRequest request) { + public QueryFetchSearchResult executeFetchPhase(QuerySearchRequest request, SearchTask task) { final SearchContext context = findContext(request.id()); context.incRef(); try { + context.setTask(task); contextProcessing(context); context.searcher().setAggregatedDfs(request.dfs()); SearchOperationListener operationListener = context.indexShard().getSearchOperationListener(); @@ -420,10 +444,11 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv } } - public ScrollQueryFetchSearchResult executeFetchPhase(InternalScrollSearchRequest request) { + public ScrollQueryFetchSearchResult executeFetchPhase(InternalScrollSearchRequest request, SearchTask task) { final SearchContext context = findContext(request.id()); context.incRef(); try { + context.setTask(task); contextProcessing(context); SearchOperationListener operationListener = context.indexShard().getSearchOperationListener(); processScroll(request, context); @@ -462,11 +487,12 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv } } - public FetchSearchResult executeFetchPhase(ShardFetchRequest request) { + public FetchSearchResult executeFetchPhase(ShardFetchRequest request, SearchTask task) { final SearchContext context = findContext(request.id()); final SearchOperationListener operationListener = context.indexShard().getSearchOperationListener(); context.incRef(); try { + context.setTask(task); contextProcessing(context); if (request.lastEmittedDoc() != null) { context.scrollContext().lastEmittedDoc = request.lastEmittedDoc(); @@ -546,6 +572,7 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv keepAlive = request.scroll().keepAlive().millis(); } context.keepAlive(keepAlive); + context.lowLevelCancellation(lowLevelCancellation); } catch (Exception e) { context.close(); throw ExceptionsHelper.convertToRuntime(e); @@ -627,6 +654,7 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv private void cleanContext(SearchContext context) { try { context.clearReleasables(Lifetime.PHASE); + context.setTask(null); } finally { context.decRef(); } diff --git a/core/src/main/java/org/elasticsearch/search/dfs/DfsPhase.java b/core/src/main/java/org/elasticsearch/search/dfs/DfsPhase.java index 1359be24a15..6be95a8bceb 100644 --- a/core/src/main/java/org/elasticsearch/search/dfs/DfsPhase.java +++ b/core/src/main/java/org/elasticsearch/search/dfs/DfsPhase.java @@ -28,9 +28,11 @@ import org.apache.lucene.index.TermContext; import org.apache.lucene.search.CollectionStatistics; import org.apache.lucene.search.TermStatistics; import org.elasticsearch.common.collect.HppcMaps; +import org.elasticsearch.search.SearchContextException; import org.elasticsearch.search.SearchPhase; import org.elasticsearch.search.internal.SearchContext; import org.elasticsearch.search.rescore.RescoreSearchContext; +import org.elasticsearch.tasks.TaskCancelledException; import java.util.AbstractSet; import java.util.Collection; @@ -59,6 +61,9 @@ public class DfsPhase implements SearchPhase { TermStatistics[] termStatistics = new TermStatistics[terms.length]; IndexReaderContext indexReaderContext = context.searcher().getTopReaderContext(); for (int i = 0; i < terms.length; i++) { + if(context.isCancelled()) { + throw new TaskCancelledException("cancelled"); + } // LUCENE 4 UPGRADE: cache TermContext? TermContext termContext = TermContext.build(indexReaderContext, terms[i]); termStatistics[i] = context.searcher().termStatistics(terms[i], termContext); @@ -70,6 +75,9 @@ public class DfsPhase implements SearchPhase { if (!fieldStatistics.containsKey(term.field())) { final CollectionStatistics collectionStatistics = context.searcher().collectionStatistics(term.field()); fieldStatistics.put(term.field(), collectionStatistics); + if(context.isCancelled()) { + throw new TaskCancelledException("cancelled"); + } } } diff --git a/core/src/main/java/org/elasticsearch/search/dfs/DfsPhaseExecutionException.java b/core/src/main/java/org/elasticsearch/search/dfs/DfsPhaseExecutionException.java index f5bcd5980a4..f493bb4d052 100644 --- a/core/src/main/java/org/elasticsearch/search/dfs/DfsPhaseExecutionException.java +++ b/core/src/main/java/org/elasticsearch/search/dfs/DfsPhaseExecutionException.java @@ -31,7 +31,11 @@ public class DfsPhaseExecutionException extends SearchContextException { super(context, "Dfs Failed [" + msg + "]", t); } + public DfsPhaseExecutionException(SearchContext context, String msg) { + super(context, "Dfs Failed [" + msg + "]"); + } + public DfsPhaseExecutionException(StreamInput in) throws IOException { super(in); } -} \ No newline at end of file +} diff --git a/core/src/main/java/org/elasticsearch/search/fetch/FetchPhase.java b/core/src/main/java/org/elasticsearch/search/fetch/FetchPhase.java index ef6fd979a69..dcf55872e35 100644 --- a/core/src/main/java/org/elasticsearch/search/fetch/FetchPhase.java +++ b/core/src/main/java/org/elasticsearch/search/fetch/FetchPhase.java @@ -51,6 +51,7 @@ import org.elasticsearch.search.internal.InternalSearchHitField; import org.elasticsearch.search.internal.InternalSearchHits; import org.elasticsearch.search.internal.SearchContext; import org.elasticsearch.search.lookup.SourceLookup; +import org.elasticsearch.tasks.TaskCancelledException; import java.io.IOException; import java.util.ArrayList; @@ -136,6 +137,9 @@ public class FetchPhase implements SearchPhase { InternalSearchHit[] hits = new InternalSearchHit[context.docIdsToLoadSize()]; FetchSubPhase.HitContext hitContext = new FetchSubPhase.HitContext(); for (int index = 0; index < context.docIdsToLoadSize(); index++) { + if(context.isCancelled()) { + throw new TaskCancelledException("cancelled"); + } int docId = context.docIdsToLoad()[context.docIdsToLoadFrom() + index]; int readerIndex = ReaderUtil.subIndex(docId, context.searcher().getIndexReader().leaves()); LeafReaderContext subReaderContext = context.searcher().getIndexReader().leaves().get(readerIndex); diff --git a/core/src/main/java/org/elasticsearch/search/fetch/FetchPhaseExecutionException.java b/core/src/main/java/org/elasticsearch/search/fetch/FetchPhaseExecutionException.java index 20d88687b0f..e3fb542134e 100644 --- a/core/src/main/java/org/elasticsearch/search/fetch/FetchPhaseExecutionException.java +++ b/core/src/main/java/org/elasticsearch/search/fetch/FetchPhaseExecutionException.java @@ -31,6 +31,10 @@ public class FetchPhaseExecutionException extends SearchContextException { super(context, "Fetch Failed [" + msg + "]", t); } + public FetchPhaseExecutionException(SearchContext context, String msg) { + super(context, "Fetch Failed [" + msg + "]"); + } + public FetchPhaseExecutionException(StreamInput in) throws IOException { super(in); } diff --git a/core/src/main/java/org/elasticsearch/search/fetch/ShardFetchRequest.java b/core/src/main/java/org/elasticsearch/search/fetch/ShardFetchRequest.java index 4087eb9a01c..2148da57d39 100644 --- a/core/src/main/java/org/elasticsearch/search/fetch/ShardFetchRequest.java +++ b/core/src/main/java/org/elasticsearch/search/fetch/ShardFetchRequest.java @@ -22,9 +22,12 @@ package org.elasticsearch.search.fetch; import com.carrotsearch.hppc.IntArrayList; import org.apache.lucene.search.FieldDoc; import org.apache.lucene.search.ScoreDoc; +import org.elasticsearch.action.search.SearchTask; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.lucene.Lucene; +import org.elasticsearch.tasks.Task; +import org.elasticsearch.tasks.TaskId; import org.elasticsearch.transport.TransportRequest; import java.io.IOException; @@ -106,4 +109,9 @@ public class ShardFetchRequest extends TransportRequest { Lucene.writeScoreDoc(out, lastEmittedDoc); } } + + @Override + public Task createTask(long id, String type, String action, TaskId parentTaskId) { + return new SearchTask(id, type, action, getDescription(), parentTaskId); + } } diff --git a/core/src/main/java/org/elasticsearch/search/internal/FilteredSearchContext.java b/core/src/main/java/org/elasticsearch/search/internal/FilteredSearchContext.java index 153a43fb895..ec5cbf145d3 100644 --- a/core/src/main/java/org/elasticsearch/search/internal/FilteredSearchContext.java +++ b/core/src/main/java/org/elasticsearch/search/internal/FilteredSearchContext.java @@ -23,6 +23,7 @@ import org.apache.lucene.search.Collector; import org.apache.lucene.search.FieldDoc; import org.apache.lucene.search.Query; import org.apache.lucene.util.Counter; +import org.elasticsearch.action.search.SearchTask; import org.elasticsearch.action.search.SearchType; import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.unit.TimeValue; @@ -293,6 +294,11 @@ public abstract class FilteredSearchContext extends SearchContext { in.terminateAfter(terminateAfter); } + @Override + public boolean lowLevelCancellation() { + return in.lowLevelCancellation(); + } + @Override public SearchContext minimumScore(float minimumScore) { return in.minimumScore(minimumScore); @@ -516,4 +522,19 @@ public abstract class FilteredSearchContext extends SearchContext { public QueryShardContext getQueryShardContext() { return in.getQueryShardContext(); } + + @Override + public void setTask(SearchTask task) { + in.setTask(task); + } + + @Override + public SearchTask getTask() { + return in.getTask(); + } + + @Override + public boolean isCancelled() { + return in.isCancelled(); + } } diff --git a/core/src/main/java/org/elasticsearch/search/internal/InternalScrollSearchRequest.java b/core/src/main/java/org/elasticsearch/search/internal/InternalScrollSearchRequest.java index 82a74de73d2..742269dba1b 100644 --- a/core/src/main/java/org/elasticsearch/search/internal/InternalScrollSearchRequest.java +++ b/core/src/main/java/org/elasticsearch/search/internal/InternalScrollSearchRequest.java @@ -20,9 +20,12 @@ package org.elasticsearch.search.internal; import org.elasticsearch.action.search.SearchScrollRequest; +import org.elasticsearch.action.search.SearchTask; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.search.Scroll; +import org.elasticsearch.tasks.Task; +import org.elasticsearch.tasks.TaskId; import org.elasticsearch.transport.TransportRequest; import java.io.IOException; @@ -67,4 +70,9 @@ public class InternalScrollSearchRequest extends TransportRequest { out.writeLong(id); out.writeOptionalWriteable(scroll); } + + @Override + public Task createTask(long id, String type, String action, TaskId parentTaskId) { + return new SearchTask(id, type, action, getDescription(), parentTaskId); + } } diff --git a/core/src/main/java/org/elasticsearch/search/internal/SearchContext.java b/core/src/main/java/org/elasticsearch/search/internal/SearchContext.java index 17f9b602f7f..ce845a84169 100644 --- a/core/src/main/java/org/elasticsearch/search/internal/SearchContext.java +++ b/core/src/main/java/org/elasticsearch/search/internal/SearchContext.java @@ -23,6 +23,7 @@ import org.apache.lucene.search.Collector; import org.apache.lucene.search.FieldDoc; import org.apache.lucene.search.Query; import org.apache.lucene.util.Counter; +import org.elasticsearch.action.search.SearchTask; import org.elasticsearch.action.search.SearchType; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.ParseFieldMatcher; @@ -96,6 +97,12 @@ public abstract class SearchContext extends AbstractRefCounted implements Releas return parseFieldMatcher; } + public abstract void setTask(SearchTask task); + + public abstract SearchTask getTask(); + + public abstract boolean isCancelled(); + @Override public final void close() { if (closed.compareAndSet(false, true)) { // prevent double closing @@ -220,6 +227,14 @@ public abstract class SearchContext extends AbstractRefCounted implements Releas public abstract void terminateAfter(int terminateAfter); + /** + * Indicates if the current index should perform frequent low level search cancellation check. + * + * Enabling low-level checks will make long running searches to react to the cancellation request faster. However, + * since it will produce more cancellation checks it might slow the search performance down. + */ + public abstract boolean lowLevelCancellation(); + public abstract SearchContext minimumScore(float minimumScore); public abstract Float minimumScore(); diff --git a/core/src/main/java/org/elasticsearch/search/internal/ShardSearchTransportRequest.java b/core/src/main/java/org/elasticsearch/search/internal/ShardSearchTransportRequest.java index 1a92257dc34..c443f1ab688 100644 --- a/core/src/main/java/org/elasticsearch/search/internal/ShardSearchTransportRequest.java +++ b/core/src/main/java/org/elasticsearch/search/internal/ShardSearchTransportRequest.java @@ -22,6 +22,7 @@ package org.elasticsearch.search.internal; import org.elasticsearch.action.IndicesRequest; import org.elasticsearch.action.OriginalIndices; import org.elasticsearch.action.search.SearchRequest; +import org.elasticsearch.action.search.SearchTask; import org.elasticsearch.action.search.SearchType; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.cluster.routing.ShardRouting; @@ -33,6 +34,8 @@ import org.elasticsearch.index.query.QueryShardContext; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.search.Scroll; import org.elasticsearch.search.builder.SearchSourceBuilder; +import org.elasticsearch.tasks.Task; +import org.elasticsearch.tasks.TaskId; import org.elasticsearch.transport.TransportRequest; import java.io.IOException; @@ -158,4 +161,9 @@ public class ShardSearchTransportRequest extends TransportRequest implements Sha public void rewrite(QueryShardContext context) throws IOException { shardSearchLocalRequest.rewrite(context); } + + @Override + public Task createTask(long id, String type, String action, TaskId parentTaskId) { + return new SearchTask(id, type, action, getDescription(), parentTaskId); + } } diff --git a/core/src/main/java/org/elasticsearch/search/profile/query/CollectorResult.java b/core/src/main/java/org/elasticsearch/search/profile/query/CollectorResult.java index c517c8730e4..6b4d7c0e842 100644 --- a/core/src/main/java/org/elasticsearch/search/profile/query/CollectorResult.java +++ b/core/src/main/java/org/elasticsearch/search/profile/query/CollectorResult.java @@ -45,6 +45,7 @@ public class CollectorResult implements ToXContent, Writeable { public static final String REASON_SEARCH_MIN_SCORE = "search_min_score"; public static final String REASON_SEARCH_MULTI = "search_multi"; public static final String REASON_SEARCH_TIMEOUT = "search_timeout"; + public static final String REASON_SEARCH_CANCELLED = "search_cancelled"; public static final String REASON_AGGREGATION = "aggregation"; public static final String REASON_AGGREGATION_GLOBAL = "aggregation_global"; diff --git a/core/src/main/java/org/elasticsearch/search/query/CancellableCollector.java b/core/src/main/java/org/elasticsearch/search/query/CancellableCollector.java new file mode 100644 index 00000000000..1c702ac0e1f --- /dev/null +++ b/core/src/main/java/org/elasticsearch/search/query/CancellableCollector.java @@ -0,0 +1,78 @@ +/* + * 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.search.query; + +import org.apache.lucene.index.LeafReaderContext; +import org.apache.lucene.search.Collector; +import org.apache.lucene.search.FilterCollector; +import org.apache.lucene.search.FilterLeafCollector; +import org.apache.lucene.search.LeafCollector; +import org.elasticsearch.common.inject.Provider; +import org.elasticsearch.tasks.TaskCancelledException; + +import java.io.IOException; + +/** + * Collector that checks if the task it is executed under is cancelled. + */ +public class CancellableCollector extends FilterCollector { + private final Provider cancelled; + private final boolean leafLevel; + + /** + * Constructor + * @param cancelled supplier of the cancellation flag, the supplier will be called for each segment if lowLevelCancellation is set + * to false and for each collected record if lowLevelCancellation is set to true. In other words this class assumes + * that the supplier is fast, with performance on the order of a volatile read. + * @param lowLevelCancellation true if collector should check for cancellation for each collected record, false if check should be + * performed only once per segment + * @param in wrapped collector + */ + public CancellableCollector(Provider cancelled, boolean lowLevelCancellation, Collector in) { + super(in); + this.cancelled = cancelled; + this.leafLevel = lowLevelCancellation; + } + + @Override + public LeafCollector getLeafCollector(LeafReaderContext context) throws IOException { + if (cancelled.get()) { + throw new TaskCancelledException("cancelled"); + } + if (leafLevel) { + return new CancellableLeafCollector(super.getLeafCollector(context)); + } else { + return super.getLeafCollector(context); + } + } + + private class CancellableLeafCollector extends FilterLeafCollector { + private CancellableLeafCollector(LeafCollector in) { + super(in); + } + + @Override + public void collect(int doc) throws IOException { + if (cancelled.get()) { + throw new TaskCancelledException("cancelled"); + } + super.collect(doc); + } + } +} diff --git a/core/src/main/java/org/elasticsearch/search/query/QueryPhase.java b/core/src/main/java/org/elasticsearch/search/query/QueryPhase.java index d1e90b2e9a5..5579e55826e 100644 --- a/core/src/main/java/org/elasticsearch/search/query/QueryPhase.java +++ b/core/src/main/java/org/elasticsearch/search/query/QueryPhase.java @@ -362,6 +362,15 @@ public class QueryPhase implements SearchPhase { } } + if (collector != null) { + final Collector child = collector; + collector = new CancellableCollector(searchContext.getTask()::isCancelled, searchContext.lowLevelCancellation(), collector); + if (doProfile) { + collector = new InternalProfileCollector(collector, CollectorResult.REASON_SEARCH_CANCELLED, + Collections.singletonList((InternalProfileCollector) child)); + } + } + try { if (collector != null) { if (doProfile) { diff --git a/core/src/main/java/org/elasticsearch/search/query/QuerySearchRequest.java b/core/src/main/java/org/elasticsearch/search/query/QuerySearchRequest.java index 3fd8ad2e84c..012d96262fc 100644 --- a/core/src/main/java/org/elasticsearch/search/query/QuerySearchRequest.java +++ b/core/src/main/java/org/elasticsearch/search/query/QuerySearchRequest.java @@ -22,10 +22,13 @@ package org.elasticsearch.search.query; import org.elasticsearch.action.IndicesRequest; import org.elasticsearch.action.OriginalIndices; import org.elasticsearch.action.search.SearchRequest; +import org.elasticsearch.action.search.SearchTask; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.search.dfs.AggregatedDfs; +import org.elasticsearch.tasks.Task; +import org.elasticsearch.tasks.TaskId; import org.elasticsearch.transport.TransportRequest; import java.io.IOException; @@ -82,4 +85,9 @@ public class QuerySearchRequest extends TransportRequest implements IndicesReque dfs.writeTo(out); OriginalIndices.writeOriginalIndices(originalIndices, out); } + + @Override + public Task createTask(long id, String type, String action, TaskId parentTaskId) { + return new SearchTask(id, type, action, getDescription(), parentTaskId); + } } diff --git a/core/src/main/java/org/elasticsearch/tasks/TaskCancelledException.java b/core/src/main/java/org/elasticsearch/tasks/TaskCancelledException.java new file mode 100644 index 00000000000..4da9eb05a68 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/tasks/TaskCancelledException.java @@ -0,0 +1,38 @@ +/* + * 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.tasks; + +import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.common.io.stream.StreamInput; + +import java.io.IOException; + +/** + * A generic exception that can be thrown by a task when it's cancelled by the task manager API + */ +public class TaskCancelledException extends ElasticsearchException { + + public TaskCancelledException(String msg) { + super(msg); + } + + public TaskCancelledException(StreamInput in) throws IOException{ + super(in); + } +} diff --git a/core/src/main/java/org/elasticsearch/tasks/TaskManager.java b/core/src/main/java/org/elasticsearch/tasks/TaskManager.java index 003a51c3175..0f2165824fe 100644 --- a/core/src/main/java/org/elasticsearch/tasks/TaskManager.java +++ b/core/src/main/java/org/elasticsearch/tasks/TaskManager.java @@ -459,7 +459,7 @@ public class TaskManager extends AbstractComponent implements ClusterStateListen if (cancellationReason == null) { nodesWithChildTasks.add(nodeId); } else { - throw new IllegalStateException("cannot register child task request, the task is already cancelled"); + throw new TaskCancelledException("cannot register child task request, the task is already cancelled"); } } } diff --git a/core/src/main/java/org/elasticsearch/transport/TaskAwareTransportRequestHandler.java b/core/src/main/java/org/elasticsearch/transport/TaskAwareTransportRequestHandler.java new file mode 100644 index 00000000000..12899d86d43 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/transport/TaskAwareTransportRequestHandler.java @@ -0,0 +1,30 @@ +/* + * 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.transport; + +/** + * Transport request handlers that is using task context + */ +public abstract class TaskAwareTransportRequestHandler implements TransportRequestHandler { + @Override + public final void messageReceived(T request, TransportChannel channel) throws Exception { + throw new UnsupportedOperationException("the task parameter is required"); + } +} diff --git a/core/src/main/java/org/elasticsearch/transport/TransportService.java b/core/src/main/java/org/elasticsearch/transport/TransportService.java index f0aa9912084..9ec3dc6b7fe 100644 --- a/core/src/main/java/org/elasticsearch/transport/TransportService.java +++ b/core/src/main/java/org/elasticsearch/transport/TransportService.java @@ -46,6 +46,8 @@ import org.elasticsearch.common.util.concurrent.ConcurrentMapLong; import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException; import org.elasticsearch.common.util.concurrent.FutureUtils; import org.elasticsearch.common.util.concurrent.ThreadContext; +import org.elasticsearch.tasks.Task; +import org.elasticsearch.tasks.TaskCancelledException; import org.elasticsearch.tasks.TaskManager; import org.elasticsearch.threadpool.ThreadPool; @@ -462,6 +464,27 @@ public class TransportService extends AbstractLifecycleComponent { asyncSender.sendRequest(node, action, request, options, handler); } + public void sendChildRequest(final DiscoveryNode node, final String action, + final TransportRequest request, final Task parentTask, + final TransportResponseHandler handler) { + sendChildRequest(node, action, request, parentTask, TransportRequestOptions.EMPTY, handler); + } + + public void sendChildRequest(final DiscoveryNode node, final String action, + final TransportRequest request, final Task parentTask, + final TransportRequestOptions options, + final TransportResponseHandler handler) { + request.setParentTask(localNode.getId(), parentTask.getId()); + try { + taskManager.registerChildTask(parentTask, node.getId()); + sendRequest(node, action, request, options, handler); + } catch (TaskCancelledException ex) { + // The parent task is already cancelled - just fail the request + handler.handleException(new TransportException(ex)); + } + + } + private void sendRequestInternal(final DiscoveryNode node, final String action, final TransportRequest request, final TransportRequestOptions options, diff --git a/core/src/test/java/org/elasticsearch/ExceptionSerializationTests.java b/core/src/test/java/org/elasticsearch/ExceptionSerializationTests.java index 0eff8d7e60c..ae2f246639d 100644 --- a/core/src/test/java/org/elasticsearch/ExceptionSerializationTests.java +++ b/core/src/test/java/org/elasticsearch/ExceptionSerializationTests.java @@ -795,6 +795,7 @@ public class ExceptionSerializationTests extends ESTestCase { ids.put(143, org.elasticsearch.script.ScriptException.class); ids.put(144, org.elasticsearch.cluster.NotMasterException.class); ids.put(145, org.elasticsearch.ElasticsearchStatusException.class); + ids.put(146, org.elasticsearch.tasks.TaskCancelledException.class); Map, Integer> reverse = new HashMap<>(); for (Map.Entry> entry : ids.entrySet()) { diff --git a/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/CancellableTasksTests.java b/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/CancellableTasksTests.java index 9027b3d372e..be2a83af42c 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/CancellableTasksTests.java +++ b/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/CancellableTasksTests.java @@ -35,6 +35,7 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.tasks.CancellableTask; import org.elasticsearch.tasks.Task; +import org.elasticsearch.tasks.TaskCancelledException; import org.elasticsearch.tasks.TaskId; import org.elasticsearch.tasks.TaskInfo; import org.elasticsearch.threadpool.ThreadPool; @@ -168,7 +169,7 @@ public class CancellableTasksTests extends TaskManagerTestCase { try { awaitBusy(() -> { if (((CancellableTask) task).isCancelled()) { - throw new RuntimeException("Cancelled"); + throw new TaskCancelledException("Cancelled"); } return false; }); diff --git a/core/src/test/java/org/elasticsearch/action/search/SearchAsyncActionTests.java b/core/src/test/java/org/elasticsearch/action/search/SearchAsyncActionTests.java index 1aafa1d343b..5ab35085e40 100644 --- a/core/src/test/java/org/elasticsearch/action/search/SearchAsyncActionTests.java +++ b/core/src/test/java/org/elasticsearch/action/search/SearchAsyncActionTests.java @@ -85,7 +85,7 @@ public class SearchAsyncActionTests extends ESTestCase { Map lookup = new HashMap<>(); lookup.put(primaryNode.getId(), primaryNode); AbstractSearchAsyncAction asyncAction = new AbstractSearchAsyncAction(logger, transportService, lookup::get, - Collections.emptyMap(), null, request, responseListener, shardsIter, 0, 0) { + Collections.emptyMap(), null, request, responseListener, shardsIter, 0, 0, null) { TestSearchResponse response = new TestSearchResponse(); @Override diff --git a/core/src/test/java/org/elasticsearch/search/SearchCancellationIT.java b/core/src/test/java/org/elasticsearch/search/SearchCancellationIT.java new file mode 100644 index 00000000000..181301a139c --- /dev/null +++ b/core/src/test/java/org/elasticsearch/search/SearchCancellationIT.java @@ -0,0 +1,297 @@ +/* + * 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.search; + +import org.elasticsearch.action.ListenableActionFuture; +import org.elasticsearch.action.admin.cluster.node.tasks.cancel.CancelTasksResponse; +import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse; +import org.elasticsearch.action.bulk.BulkRequestBuilder; +import org.elasticsearch.action.search.SearchAction; +import org.elasticsearch.action.search.SearchPhaseExecutionException; +import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.action.search.SearchScrollAction; +import org.elasticsearch.action.support.WriteRequest; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.plugins.Plugin; +import org.elasticsearch.plugins.PluginsService; +import org.elasticsearch.plugins.ScriptPlugin; +import org.elasticsearch.script.AbstractSearchScript; +import org.elasticsearch.script.ExecutableScript; +import org.elasticsearch.script.NativeScriptFactory; +import org.elasticsearch.script.Script; +import org.elasticsearch.script.ScriptService.ScriptType; +import org.elasticsearch.tasks.TaskInfo; +import org.elasticsearch.test.ESIntegTestCase; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; + +import static org.elasticsearch.index.query.QueryBuilders.scriptQuery; +import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.hasSize; + +@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.SUITE) +public class SearchCancellationIT extends ESIntegTestCase { + + @Override + protected Collection> nodePlugins() { + return Collections.singleton(ScriptedBlockPlugin.class); + } + + @Override + protected Settings nodeSettings(int nodeOrdinal) { + return Settings.builder().put(SearchService.LOW_LEVEL_CANCELLATION_SETTING.getKey(), randomBoolean()).build(); + } + + private void indexTestData() { + for (int i = 0; i < 10; i++) { + // Make sure we have a few segments + BulkRequestBuilder bulkRequestBuilder = client().prepareBulk().setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); + for(int j=0; j<10; j++) { + bulkRequestBuilder.add(client().prepareIndex("test", "type", Integer.toString(i*10 + j)).setSource("field", "value")); + } + assertNoFailures(bulkRequestBuilder.get()); + } + } + + private List initBlockFactory() { + List plugins = new ArrayList<>(); + for (PluginsService pluginsService : internalCluster().getDataNodeInstances(PluginsService.class)) { + plugins.addAll(pluginsService.filterPlugins(ScriptedBlockPlugin.class)); + } + for (ScriptedBlockPlugin plugin : plugins) { + plugin.scriptedBlockFactory.reset(); + plugin.scriptedBlockFactory.enableBlock(); + } + return plugins; + } + + private void awaitForBlock(List plugins) throws Exception { + int numberOfShards = getNumShards("test").numPrimaries; + assertBusy(() -> { + int numberOfBlockedPlugins = 0; + for (ScriptedBlockPlugin plugin : plugins) { + numberOfBlockedPlugins += plugin.scriptedBlockFactory.hits.get(); + } + logger.info("The plugin blocked on {} out of {} shards", numberOfBlockedPlugins, numberOfShards); + assertThat(numberOfBlockedPlugins, greaterThan(0)); + }); + } + + private void disableBlocks(List plugins) throws Exception { + for (ScriptedBlockPlugin plugin : plugins) { + plugin.scriptedBlockFactory.disableBlock(); + } + } + + private void cancelSearch(String action) { + ListTasksResponse listTasksResponse = client().admin().cluster().prepareListTasks().setActions(action).get(); + assertThat(listTasksResponse.getTasks(), hasSize(1)); + TaskInfo searchTask = listTasksResponse.getTasks().get(0); + + logger.info("Cancelling search"); + CancelTasksResponse cancelTasksResponse = client().admin().cluster().prepareCancelTasks().setTaskId(searchTask.getTaskId()).get(); + assertThat(cancelTasksResponse.getTasks(), hasSize(1)); + assertThat(cancelTasksResponse.getTasks().get(0).getTaskId(), equalTo(searchTask.getTaskId())); + } + + private SearchResponse ensureSearchWasCancelled(ListenableActionFuture searchResponse) { + try { + SearchResponse response = searchResponse.actionGet(); + logger.info("Search response {}", response); + assertNotEquals("At least one shard should have failed", 0, response.getFailedShards()); + return response; + } catch (SearchPhaseExecutionException ex) { + logger.info("All shards failed with", ex); + return null; + } + } + + public void testCancellationDuringQueryPhase() throws Exception { + + List plugins = initBlockFactory(); + indexTestData(); + + logger.info("Executing search"); + ListenableActionFuture searchResponse = client().prepareSearch("test").setQuery( + scriptQuery(new Script(NativeTestScriptedBlockFactory.TEST_NATIVE_BLOCK_SCRIPT, ScriptType.INLINE, "native", null))) + .execute(); + + awaitForBlock(plugins); + cancelSearch(SearchAction.NAME); + disableBlocks(plugins); + ensureSearchWasCancelled(searchResponse); + } + + public void testCancellationDuringFetchPhase() throws Exception { + + List plugins = initBlockFactory(); + indexTestData(); + + logger.info("Executing search"); + ListenableActionFuture searchResponse = client().prepareSearch("test") + .addScriptField("test_field", + new Script(NativeTestScriptedBlockFactory.TEST_NATIVE_BLOCK_SCRIPT, ScriptType.INLINE, "native", null) + ).execute(); + + awaitForBlock(plugins); + cancelSearch(SearchAction.NAME); + disableBlocks(plugins); + ensureSearchWasCancelled(searchResponse); + } + + public void testCancellationOfScrollSearches() throws Exception { + + List plugins = initBlockFactory(); + indexTestData(); + + logger.info("Executing search"); + ListenableActionFuture searchResponse = client().prepareSearch("test") + .setScroll(TimeValue.timeValueSeconds(10)) + .setSize(5) + .setQuery( + scriptQuery(new Script(NativeTestScriptedBlockFactory.TEST_NATIVE_BLOCK_SCRIPT, ScriptType.INLINE, "native", null))) + .execute(); + + awaitForBlock(plugins); + cancelSearch(SearchAction.NAME); + disableBlocks(plugins); + ensureSearchWasCancelled(searchResponse); + } + + + public void testCancellationOfScrollSearchesOnFollowupRequests() throws Exception { + + List plugins = initBlockFactory(); + indexTestData(); + + // Disable block so the first request would pass + disableBlocks(plugins); + + logger.info("Executing search"); + TimeValue keepAlive = TimeValue.timeValueSeconds(5); + SearchResponse searchResponse = client().prepareSearch("test") + .setScroll(keepAlive) + .setSize(2) + .setQuery( + scriptQuery(new Script(NativeTestScriptedBlockFactory.TEST_NATIVE_BLOCK_SCRIPT, ScriptType.INLINE, "native", null))) + .get(); + + assertNotNull(searchResponse.getScrollId()); + + // Enable block so the second request would block + for (ScriptedBlockPlugin plugin : plugins) { + plugin.scriptedBlockFactory.reset(); + plugin.scriptedBlockFactory.enableBlock(); + } + + String scrollId = searchResponse.getScrollId(); + logger.info("Executing scroll with id {}", scrollId); + ListenableActionFuture scrollResponse = client().prepareSearchScroll(searchResponse.getScrollId()) + .setScroll(keepAlive).execute(); + + awaitForBlock(plugins); + cancelSearch(SearchScrollAction.NAME); + disableBlocks(plugins); + + SearchResponse response = ensureSearchWasCancelled(scrollResponse); + if (response != null){ + // The response didn't fail completely - update scroll id + scrollId = response.getScrollId(); + } + logger.info("Cleaning scroll with id {}", scrollId); + client().prepareClearScroll().addScrollId(scrollId).get(); + } + + + public static class ScriptedBlockPlugin extends Plugin implements ScriptPlugin { + private NativeTestScriptedBlockFactory scriptedBlockFactory; + + public ScriptedBlockPlugin() { + scriptedBlockFactory = new NativeTestScriptedBlockFactory(); + } + + @Override + public List getNativeScripts() { + return Collections.singletonList(scriptedBlockFactory); + } + } + + private static class NativeTestScriptedBlockFactory implements NativeScriptFactory { + + public static final String TEST_NATIVE_BLOCK_SCRIPT = "native_test_search_block_script"; + + private final AtomicInteger hits = new AtomicInteger(); + + private final AtomicBoolean shouldBlock = new AtomicBoolean(true); + + public NativeTestScriptedBlockFactory() { + } + + public void reset() { + hits.set(0); + } + + public void disableBlock() { + shouldBlock.set(false); + } + + public void enableBlock() { + shouldBlock.set(true); + } + + @Override + public ExecutableScript newScript(Map params) { + return new NativeTestScriptedBlock(); + } + + @Override + public boolean needsScores() { + return false; + } + + @Override + public String getName() { + return TEST_NATIVE_BLOCK_SCRIPT; + } + + public class NativeTestScriptedBlock extends AbstractSearchScript { + @Override + public Object run() { + hits.incrementAndGet(); + try { + awaitBusy(() -> shouldBlock.get() == false); + } catch (Exception e) { + throw new RuntimeException(e); + } + return true; + } + } + } + +} diff --git a/core/src/test/java/org/elasticsearch/search/SearchCancellationTests.java b/core/src/test/java/org/elasticsearch/search/SearchCancellationTests.java new file mode 100644 index 00000000000..5026be9d521 --- /dev/null +++ b/core/src/test/java/org/elasticsearch/search/SearchCancellationTests.java @@ -0,0 +1,97 @@ +/* + * 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.search; + +import org.apache.lucene.document.Document; +import org.apache.lucene.document.Field; +import org.apache.lucene.document.StringField; +import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.RandomIndexWriter; +import org.apache.lucene.search.LeafCollector; +import org.apache.lucene.search.TotalHitCountCollector; +import org.apache.lucene.store.Directory; +import org.apache.lucene.util.IOUtils; +import org.apache.lucene.util.TestUtil; +import org.elasticsearch.search.query.CancellableCollector; +import org.elasticsearch.tasks.TaskCancelledException; +import org.elasticsearch.test.ESTestCase; +import org.junit.AfterClass; +import org.junit.BeforeClass; + +import java.io.IOException; +import java.util.concurrent.atomic.AtomicBoolean; + +public class SearchCancellationTests extends ESTestCase { + + static Directory dir; + static IndexReader reader; + + @BeforeClass + public static void before() throws IOException { + dir = newDirectory(); + RandomIndexWriter w = new RandomIndexWriter(random(), dir); + indexRandomDocuments(w, TestUtil.nextInt(random(), 2, 20)); + w.flush(); + indexRandomDocuments(w, TestUtil.nextInt(random(), 1, 20)); + reader = w.getReader(); + w.close(); + } + + private static void indexRandomDocuments(RandomIndexWriter w, int numDocs) throws IOException { + for (int i = 0; i < numDocs; ++i) { + final int numHoles = random().nextInt(5); + for (int j = 0; j < numHoles; ++j) { + w.addDocument(new Document()); + } + Document doc = new Document(); + doc.add(new StringField("foo", "bar", Field.Store.NO)); + w.addDocument(doc); + } + } + + @AfterClass + public static void after() throws IOException { + IOUtils.close(reader, dir); + dir = null; + reader = null; + } + + + public void testLowLevelCancellableCollector() throws IOException { + TotalHitCountCollector collector = new TotalHitCountCollector(); + AtomicBoolean cancelled = new AtomicBoolean(); + CancellableCollector cancellableCollector = new CancellableCollector(cancelled::get, true, collector); + final LeafCollector leafCollector = cancellableCollector.getLeafCollector(reader.leaves().get(0)); + leafCollector.collect(0); + cancelled.set(true); + expectThrows(TaskCancelledException.class, () -> leafCollector.collect(1)); + } + + public void testCancellableCollector() throws IOException { + TotalHitCountCollector collector = new TotalHitCountCollector(); + AtomicBoolean cancelled = new AtomicBoolean(); + CancellableCollector cancellableCollector = new CancellableCollector(cancelled::get, false, collector); + final LeafCollector leafCollector = cancellableCollector.getLeafCollector(reader.leaves().get(0)); + leafCollector.collect(0); + cancelled.set(true); + leafCollector.collect(1); + expectThrows(TaskCancelledException.class, () -> cancellableCollector.getLeafCollector(reader.leaves().get(1))); + } + +} diff --git a/core/src/test/java/org/elasticsearch/search/SearchServiceTests.java b/core/src/test/java/org/elasticsearch/search/SearchServiceTests.java index 0def6726e03..717d64a53e7 100644 --- a/core/src/test/java/org/elasticsearch/search/SearchServiceTests.java +++ b/core/src/test/java/org/elasticsearch/search/SearchServiceTests.java @@ -25,6 +25,7 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.index.IndexResponse; import org.elasticsearch.action.search.SearchPhaseExecutionException; import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.action.search.SearchTask; import org.elasticsearch.action.search.SearchType; import org.elasticsearch.action.support.WriteRequest; import org.elasticsearch.common.Strings; @@ -175,11 +176,12 @@ public class SearchServiceTests extends ESSingleNodeTestCase { try { QuerySearchResultProvider querySearchResultProvider = service.executeQueryPhase( new ShardSearchLocalRequest(indexShard.shardId(), 1, SearchType.DEFAULT, - new SearchSourceBuilder(), new String[0], false, new AliasFilter(null, Strings.EMPTY_ARRAY))); + new SearchSourceBuilder(), new String[0], false, new AliasFilter(null, Strings.EMPTY_ARRAY)), + new SearchTask(123L, "", "", "", null)); IntArrayList intCursors = new IntArrayList(1); intCursors.add(0); ShardFetchRequest req = new ShardFetchRequest(querySearchResultProvider.id(), intCursors, null /* not a scroll */); - service.executeFetchPhase(req); + service.executeFetchPhase(req, new SearchTask(123L, "", "", "", null)); } catch (AlreadyClosedException ex) { throw ex; } catch (IllegalStateException ex) { diff --git a/core/src/test/java/org/elasticsearch/search/query/QueryPhaseTests.java b/core/src/test/java/org/elasticsearch/search/query/QueryPhaseTests.java index 5bbae82b7d7..65aa5f992e6 100644 --- a/core/src/test/java/org/elasticsearch/search/query/QueryPhaseTests.java +++ b/core/src/test/java/org/elasticsearch/search/query/QueryPhaseTests.java @@ -40,6 +40,7 @@ import org.apache.lucene.search.Query; import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.Weight; import org.apache.lucene.store.Directory; +import org.elasticsearch.action.search.SearchTask; import org.elasticsearch.index.query.ParsedQuery; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.TestSearchContext; @@ -54,6 +55,7 @@ public class QueryPhaseTests extends ESTestCase { TestSearchContext context = new TestSearchContext(null); context.parsedQuery(new ParsedQuery(query)); context.setSize(0); + context.setTask(new SearchTask(123L, "", "", "", null)); IndexSearcher searcher = new IndexSearcher(reader); final AtomicBoolean collected = new AtomicBoolean(); @@ -123,6 +125,7 @@ public class QueryPhaseTests extends ESTestCase { TestSearchContext context = new TestSearchContext(null); context.parsedQuery(new ParsedQuery(new MatchAllDocsQuery())); context.setSize(0); + context.setTask(new SearchTask(123L, "", "", "", null)); final AtomicBoolean collected = new AtomicBoolean(); IndexSearcher contextSearcher = new IndexSearcher(new MultiReader()) { @@ -146,6 +149,7 @@ public class QueryPhaseTests extends ESTestCase { TestSearchContext context = new TestSearchContext(null); context.parsedQuery(new ParsedQuery(new MatchAllDocsQuery())); context.setSize(0); + context.setTask(new SearchTask(123L, "", "", "", null)); final AtomicBoolean collected = new AtomicBoolean(); IndexSearcher contextSearcher = new IndexSearcher(new MultiReader()) { diff --git a/docs/reference/cluster/tasks.asciidoc b/docs/reference/cluster/tasks.asciidoc index 2176a432291..ce550a689bf 100644 --- a/docs/reference/cluster/tasks.asciidoc +++ b/docs/reference/cluster/tasks.asciidoc @@ -108,6 +108,7 @@ GET _cat/tasks // CONSOLE [float] +[[task-cancellation]] === Task Cancellation If a long-running task supports cancellation, it can be cancelled by the following command: diff --git a/docs/reference/search.asciidoc b/docs/reference/search.asciidoc index 61d807cc212..7a26ee2cf60 100644 --- a/docs/reference/search.asciidoc +++ b/docs/reference/search.asciidoc @@ -92,6 +92,19 @@ timeout. The setting key is `search.default_search_timeout` and can be set using the <> endpoints. Setting this value to `-1` resets the global search timeout to no timeout. +[float] +[[global-search-cancellation]] +== Search Cancellation + +Searches can be cancelled using standard <> +mechanism. By default, a running search only checks if it is cancelled or +not on segment boundaries, therefore the cancellation can be delayed by large +segments. The search cancellation responsiveness can be improved by setting +the dynamic cluster-level setting `search.low_level_cancellation` to `true`. +However, it comes with an additional overhead of more frequent cancellation +checks that can be noticeable on large fast running search queries. Changing this +setting only affects the searches that start after the change is made. + -- include::search/search.asciidoc[] diff --git a/docs/reference/search/profile.asciidoc b/docs/reference/search/profile.asciidoc index 0a03b322858..52b744d30e9 100644 --- a/docs/reference/search/profile.asciidoc +++ b/docs/reference/search/profile.asciidoc @@ -118,9 +118,16 @@ This will yield the following result: "rewrite_time": 51443, "collector": [ { - "name": "SimpleTopScoreDocCollector", - "reason": "search_top_hits", - "time": "0.06989100000ms" + "name": "CancellableCollector", + "reason": "search_cancelled", + "time": "0.3043110000ms", + "children": [ + { + "name": "SimpleTopScoreDocCollector", + "reason": "search_top_hits", + "time": "0.03227300000ms" + } + ] } ] } @@ -150,7 +157,8 @@ This will yield the following result: // TESTRESPONSE[s/"build_scorer": 42602/"build_scorer": $body.profile.shards.0.searches.0.query.0.children.1.breakdown.build_scorer/] // TESTRESPONSE[s/"create_weight": 89323/"create_weight": $body.profile.shards.0.searches.0.query.0.children.1.breakdown.create_weight/] // TESTRESPONSE[s/"next_doc": 2852/"next_doc": $body.profile.shards.0.searches.0.query.0.children.1.breakdown.next_doc/] -// TESTRESPONSE[s/"time": "0.06989100000ms"/"time": $body.profile.shards.0.searches.0.collector.0.time/] +// TESTRESPONSE[s/"time": "0.3043110000ms"/"time": $body.profile.shards.0.searches.0.collector.0.time/] +// TESTRESPONSE[s/"time": "0.03227300000ms"/"time": $body.profile.shards.0.searches.0.collector.0.children.0.time/] // Sorry for this mess.... <1> Search results are returned, but were omitted here for brevity @@ -390,21 +398,30 @@ Looking at the previous example: [source,js] -------------------------------------------------- "collector": [ - { - "name": "SimpleTopScoreDocCollector", - "reason": "search_top_hits", - "time": "0.06989100000ms" - } + { + "name": "CancellableCollector", + "reason": "search_cancelled", + "time": "0.3043110000ms", + "children": [ + { + "name": "SimpleTopScoreDocCollector", + "reason": "search_top_hits", + "time": "0.03227300000ms" + } + ] + } ] -------------------------------------------------- // TESTRESPONSE[s/^/{\n"took": $body.took,\n"timed_out": $body.timed_out,\n"_shards": $body._shards,\n"hits": $body.hits,\n"profile": {\n"shards": [ {\n"id": "$body.profile.shards.0.id",\n"searches": [{\n"query": $body.profile.shards.0.searches.0.query,\n"rewrite_time": $body.profile.shards.0.searches.0.rewrite_time,/] // TESTRESPONSE[s/]$/]}], "aggregations": []}]}}/] -// TESTRESPONSE[s/"time": "0.06989100000ms"/"time": $body.profile.shards.0.searches.0.collector.0.time/] +// TESTRESPONSE[s/"time": "0.3043110000ms"/"time": $body.profile.shards.0.searches.0.collector.0.time/] +// TESTRESPONSE[s/"time": "0.03227300000ms"/"time": $body.profile.shards.0.searches.0.collector.0.children.0.time/] -We see a single collector named `SimpleTopScoreDocCollector`. This is the default "scoring and sorting" Collector -used by Elasticsearch. The `"reason"` field attempts to give a plain english description of the class name. The +We see a single collector named `SimpleTopScoreDocCollector` wrapped into `CancellableCollector`. `SimpleTopScoreDocCollector` is the default "scoring and sorting" +`Collector` used by Elasticsearch. The `"reason"` field attempts to give a plain english description of the class name. The `"time"` is similar to the time in the Query tree: a wall-clock time inclusive of all children. Similarly, `children` lists -all sub-collectors. +all sub-collectors. The `CancellableCollector` that wraps `SimpleTopScoreDocCollector` is used by elasticsearch to detect if the current +search was cancelled and stop collecting documents as soon as it occurs. It should be noted that Collector times are **independent** from the Query times. They are calculated, combined and normalized independently! Due to the nature of Lucene's execution, it is impossible to "merge" the times diff --git a/test/framework/src/main/java/org/elasticsearch/test/TestSearchContext.java b/test/framework/src/main/java/org/elasticsearch/test/TestSearchContext.java index aa041a12195..e4c0e1d5abc 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/TestSearchContext.java +++ b/test/framework/src/main/java/org/elasticsearch/test/TestSearchContext.java @@ -22,6 +22,7 @@ import org.apache.lucene.search.Collector; import org.apache.lucene.search.FieldDoc; import org.apache.lucene.search.Query; import org.apache.lucene.util.Counter; +import org.elasticsearch.action.search.SearchTask; import org.elasticsearch.action.search.SearchType; import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.unit.TimeValue; @@ -80,6 +81,7 @@ public class TestSearchContext extends SearchContext { ParsedQuery postFilter; Query query; Float minScore; + SearchTask task; ContextIndexSearcher searcher; int size; @@ -324,6 +326,11 @@ public class TestSearchContext extends SearchContext { this.terminateAfter = terminateAfter; } + @Override + public boolean lowLevelCancellation() { + return false; + } + @Override public SearchContext minimumScore(float minimumScore) { this.minScore = minimumScore; @@ -571,4 +578,18 @@ public class TestSearchContext extends SearchContext { return queryShardContext; } + @Override + public void setTask(SearchTask task) { + this.task = task; + } + + @Override + public SearchTask getTask() { + return task; + } + + @Override + public boolean isCancelled() { + return task.isCancelled(); + } } From 9c3e4d6e228a16aa6660b77f80797999a8ee629f Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 25 Oct 2016 23:08:19 -0400 Subject: [PATCH 11/19] Add correct Content-Length on HEAD requests This commit fixes responses to HEAD requests so that the value of the Content-Length is correct per the HTTP spec. Namely, the value of this header should be equal to the Content-Length if the request were not a HEAD request. This commit also fixes a memory leak on HEAD requests to the main action that arose from the bytes on a builder not being released due to them being dropped on the floor to ensure that the response to the main action did not have a body. Relates #21123 --- .../rest/action/RestMainAction.java | 3 -- .../rest/action/RestMainActionTests.java | 4 +-- .../http/netty3/Netty3HttpChannel.java | 8 ++++- .../rest/Netty3HeadBodyIsEmptyIT.java | 23 +++++++++++++ .../http/netty4/Netty4HttpChannel.java | 10 ++++-- .../rest/Netty4HeadBodyIsEmptyIT.java | 23 +++++++++++++ .../rest/HeadBodyIsEmptyIntegTestCase.java | 32 ++++++++++--------- 7 files changed, 80 insertions(+), 23 deletions(-) create mode 100644 modules/transport-netty3/src/test/java/org/elasticsearch/rest/Netty3HeadBodyIsEmptyIT.java create mode 100644 modules/transport-netty4/src/test/java/org/elasticsearch/rest/Netty4HeadBodyIsEmptyIT.java rename distribution/integ-test-zip/src/test/java/org/elasticsearch/test/rest/HeadBodyIsEmptyIT.java => test/framework/src/main/java/org/elasticsearch/rest/HeadBodyIsEmptyIntegTestCase.java (70%) diff --git a/core/src/main/java/org/elasticsearch/rest/action/RestMainAction.java b/core/src/main/java/org/elasticsearch/rest/action/RestMainAction.java index c1c1e220b28..210ccb2e227 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/RestMainAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/RestMainAction.java @@ -60,9 +60,6 @@ public class RestMainAction extends BaseRestHandler { static BytesRestResponse convertMainResponse(MainResponse response, RestRequest request, XContentBuilder builder) throws IOException { RestStatus status = response.isAvailable() ? RestStatus.OK : RestStatus.SERVICE_UNAVAILABLE; - if (request.method() == RestRequest.Method.HEAD) { - return new BytesRestResponse(status, BytesRestResponse.TEXT_CONTENT_TYPE, BytesArray.EMPTY); - } // Default to pretty printing, but allow ?pretty=false to disable if (request.hasParam("pretty") == false) { diff --git a/core/src/test/java/org/elasticsearch/rest/action/RestMainActionTests.java b/core/src/test/java/org/elasticsearch/rest/action/RestMainActionTests.java index bef1ed44ac6..449f5852cfa 100644 --- a/core/src/test/java/org/elasticsearch/rest/action/RestMainActionTests.java +++ b/core/src/test/java/org/elasticsearch/rest/action/RestMainActionTests.java @@ -61,9 +61,9 @@ public class RestMainActionTests extends ESTestCase { BytesRestResponse response = RestMainAction.convertMainResponse(mainResponse, restRequest, builder); assertNotNull(response); assertEquals(expectedStatus, response.status()); - assertEquals(0, response.content().length()); - assertEquals(0, builder.bytes().length()); + // the empty responses are handled in the HTTP layer so we do + // not assert on them here } public void testGetResponse() throws Exception { diff --git a/modules/transport-netty3/src/main/java/org/elasticsearch/http/netty3/Netty3HttpChannel.java b/modules/transport-netty3/src/main/java/org/elasticsearch/http/netty3/Netty3HttpChannel.java index a715abfd877..d79fae21b8c 100644 --- a/modules/transport-netty3/src/main/java/org/elasticsearch/http/netty3/Netty3HttpChannel.java +++ b/modules/transport-netty3/src/main/java/org/elasticsearch/http/netty3/Netty3HttpChannel.java @@ -33,6 +33,7 @@ import org.elasticsearch.rest.AbstractRestChannel; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; import org.jboss.netty.buffer.ChannelBuffer; +import org.jboss.netty.buffer.ChannelBuffers; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelFuture; import org.jboss.netty.channel.ChannelFutureListener; @@ -41,6 +42,7 @@ import org.jboss.netty.handler.codec.http.CookieDecoder; import org.jboss.netty.handler.codec.http.CookieEncoder; import org.jboss.netty.handler.codec.http.DefaultHttpResponse; import org.jboss.netty.handler.codec.http.HttpHeaders; +import org.jboss.netty.handler.codec.http.HttpMethod; import org.jboss.netty.handler.codec.http.HttpResponse; import org.jboss.netty.handler.codec.http.HttpResponseStatus; import org.jboss.netty.handler.codec.http.HttpVersion; @@ -109,7 +111,11 @@ public final class Netty3HttpChannel extends AbstractRestChannel { boolean addedReleaseListener = false; try { buffer = Netty3Utils.toChannelBuffer(content); - resp.setContent(buffer); + if (HttpMethod.HEAD.equals(nettyRequest.getMethod())) { + resp.setContent(ChannelBuffers.EMPTY_BUFFER); + } else { + resp.setContent(buffer); + } // If our response doesn't specify a content-type header, set one setHeaderField(resp, HttpHeaders.Names.CONTENT_TYPE, response.contentType(), false); diff --git a/modules/transport-netty3/src/test/java/org/elasticsearch/rest/Netty3HeadBodyIsEmptyIT.java b/modules/transport-netty3/src/test/java/org/elasticsearch/rest/Netty3HeadBodyIsEmptyIT.java new file mode 100644 index 00000000000..82e5ff9b666 --- /dev/null +++ b/modules/transport-netty3/src/test/java/org/elasticsearch/rest/Netty3HeadBodyIsEmptyIT.java @@ -0,0 +1,23 @@ +/* + * 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.rest; + +public class Netty3HeadBodyIsEmptyIT extends HeadBodyIsEmptyIntegTestCase { +} diff --git a/modules/transport-netty4/src/main/java/org/elasticsearch/http/netty4/Netty4HttpChannel.java b/modules/transport-netty4/src/main/java/org/elasticsearch/http/netty4/Netty4HttpChannel.java index e9bb129cf6d..efcc8d1f2ea 100644 --- a/modules/transport-netty4/src/main/java/org/elasticsearch/http/netty4/Netty4HttpChannel.java +++ b/modules/transport-netty4/src/main/java/org/elasticsearch/http/netty4/Netty4HttpChannel.java @@ -20,6 +20,7 @@ package org.elasticsearch.http.netty4; import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; import io.netty.channel.Channel; import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelPromise; @@ -29,6 +30,7 @@ import io.netty.handler.codec.http.FullHttpResponse; import io.netty.handler.codec.http.HttpHeaderNames; import io.netty.handler.codec.http.HttpHeaderValues; import io.netty.handler.codec.http.HttpHeaders; +import io.netty.handler.codec.http.HttpMethod; import io.netty.handler.codec.http.HttpResponse; import io.netty.handler.codec.http.HttpResponseStatus; import io.netty.handler.codec.http.HttpVersion; @@ -87,13 +89,17 @@ final class Netty4HttpChannel extends AbstractRestChannel { return new ReleasableBytesStreamOutput(transport.bigArrays); } - @Override public void sendResponse(RestResponse response) { // if the response object was created upstream, then use it; // otherwise, create a new one ByteBuf buffer = Netty4Utils.toByteBuf(response.content()); - FullHttpResponse resp = newResponse(buffer); + final FullHttpResponse resp; + if (HttpMethod.HEAD.equals(nettyRequest.method())) { + resp = newResponse(Unpooled.EMPTY_BUFFER); + } else { + resp = newResponse(buffer); + } resp.setStatus(getStatus(response.status())); Netty4CorsHandler.setCorsResponseHeaders(nettyRequest, resp, transport.getCorsConfig()); diff --git a/modules/transport-netty4/src/test/java/org/elasticsearch/rest/Netty4HeadBodyIsEmptyIT.java b/modules/transport-netty4/src/test/java/org/elasticsearch/rest/Netty4HeadBodyIsEmptyIT.java new file mode 100644 index 00000000000..8716f59ee00 --- /dev/null +++ b/modules/transport-netty4/src/test/java/org/elasticsearch/rest/Netty4HeadBodyIsEmptyIT.java @@ -0,0 +1,23 @@ +/* + * 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.rest; + +public class Netty4HeadBodyIsEmptyIT extends HeadBodyIsEmptyIntegTestCase { +} diff --git a/distribution/integ-test-zip/src/test/java/org/elasticsearch/test/rest/HeadBodyIsEmptyIT.java b/test/framework/src/main/java/org/elasticsearch/rest/HeadBodyIsEmptyIntegTestCase.java similarity index 70% rename from distribution/integ-test-zip/src/test/java/org/elasticsearch/test/rest/HeadBodyIsEmptyIT.java rename to test/framework/src/main/java/org/elasticsearch/rest/HeadBodyIsEmptyIntegTestCase.java index c3a19e5ab34..0e43814b75c 100644 --- a/distribution/integ-test-zip/src/test/java/org/elasticsearch/test/rest/HeadBodyIsEmptyIT.java +++ b/test/framework/src/main/java/org/elasticsearch/rest/HeadBodyIsEmptyIntegTestCase.java @@ -17,10 +17,12 @@ * under the License. */ -package org.elasticsearch.test.rest; +package org.elasticsearch.rest; import org.apache.http.entity.StringEntity; import org.elasticsearch.client.Response; +import org.elasticsearch.test.rest.ESRestTestCase; +import org.hamcrest.Matcher; import java.io.IOException; import java.io.UnsupportedEncodingException; @@ -28,15 +30,17 @@ import java.util.Map; import static java.util.Collections.emptyMap; import static java.util.Collections.singletonMap; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.Matchers.greaterThan; /** * Tests that HTTP HEAD requests don't respond with a body. */ -public class HeadBodyIsEmptyIT extends ESRestTestCase { +public class HeadBodyIsEmptyIntegTestCase extends ESRestTestCase { public void testHeadRoot() throws IOException { - headTestCase("/", emptyMap()); - headTestCase("/", singletonMap("pretty", "")); - headTestCase("/", singletonMap("pretty", "true")); + headTestCase("/", emptyMap(), greaterThan(0)); + headTestCase("/", singletonMap("pretty", ""), greaterThan(0)); + headTestCase("/", singletonMap("pretty", "true"), greaterThan(0)); } private void createTestDoc() throws UnsupportedEncodingException, IOException { @@ -45,28 +49,26 @@ public class HeadBodyIsEmptyIT extends ESRestTestCase { public void testDocumentExists() throws IOException { createTestDoc(); - headTestCase("test/test/1", emptyMap()); - headTestCase("test/test/1", singletonMap("pretty", "true")); + headTestCase("test/test/1", emptyMap(), equalTo(0)); + headTestCase("test/test/1", singletonMap("pretty", "true"), equalTo(0)); } public void testIndexExists() throws IOException { createTestDoc(); - headTestCase("test", emptyMap()); - headTestCase("test", singletonMap("pretty", "true")); + headTestCase("test", emptyMap(), equalTo(0)); + headTestCase("test", singletonMap("pretty", "true"), equalTo(0)); } public void testTypeExists() throws IOException { createTestDoc(); - headTestCase("test/test", emptyMap()); - headTestCase("test/test", singletonMap("pretty", "true")); + headTestCase("test/test", emptyMap(), equalTo(0)); + headTestCase("test/test", singletonMap("pretty", "true"), equalTo(0)); } - private void headTestCase(String url, Map params) throws IOException { + private void headTestCase(String url, Map params, Matcher matcher) throws IOException { Response response = client().performRequest("HEAD", url, params); assertEquals(200, response.getStatusLine().getStatusCode()); - /* Check that the content-length header is always 0. This isn't what we should be doing in the long run but it is what we expect - * that we are *actually* doing. */ - assertEquals("We expect HEAD requests to have 0 Content-Length but " + url + " didn't", "0", response.getHeader("Content-Length")); + assertThat(Integer.valueOf(response.getHeader("Content-Length")), matcher); assertNull("HEAD requests shouldn't have a response body but " + url + " did", response.getEntity()); } } From 6fe3bd817bb4a5aeebc4e17f5fc145e565efde84 Mon Sep 17 00:00:00 2001 From: Igor Motov Date: Tue, 25 Oct 2016 19:36:07 -1000 Subject: [PATCH 12/19] Tests: make sure that 2 segments are created in SearchCancellationTests Otherwise, the test fails if forced merge kicks in. --- .../java/org/elasticsearch/search/SearchCancellationTests.java | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/test/java/org/elasticsearch/search/SearchCancellationTests.java b/core/src/test/java/org/elasticsearch/search/SearchCancellationTests.java index 5026be9d521..a50b7edf57a 100644 --- a/core/src/test/java/org/elasticsearch/search/SearchCancellationTests.java +++ b/core/src/test/java/org/elasticsearch/search/SearchCancellationTests.java @@ -46,6 +46,7 @@ public class SearchCancellationTests extends ESTestCase { public static void before() throws IOException { dir = newDirectory(); RandomIndexWriter w = new RandomIndexWriter(random(), dir); + w.setDoRandomForceMerge(false); // we need 2 segments indexRandomDocuments(w, TestUtil.nextInt(random(), 2, 20)); w.flush(); indexRandomDocuments(w, TestUtil.nextInt(random(), 1, 20)); From e6dda02c666959d415cc753a16291042d1c133ee Mon Sep 17 00:00:00 2001 From: Igor Motov Date: Tue, 25 Oct 2016 19:52:51 -1000 Subject: [PATCH 13/19] Tests: silence cancelling scroll search tests Investigating it locally --- .../java/org/elasticsearch/search/SearchCancellationIT.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/src/test/java/org/elasticsearch/search/SearchCancellationIT.java b/core/src/test/java/org/elasticsearch/search/SearchCancellationIT.java index 181301a139c..365f6df9f7c 100644 --- a/core/src/test/java/org/elasticsearch/search/SearchCancellationIT.java +++ b/core/src/test/java/org/elasticsearch/search/SearchCancellationIT.java @@ -165,6 +165,7 @@ public class SearchCancellationIT extends ESIntegTestCase { ensureSearchWasCancelled(searchResponse); } + @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/21126") public void testCancellationOfScrollSearches() throws Exception { List plugins = initBlockFactory(); @@ -185,6 +186,7 @@ public class SearchCancellationIT extends ESIntegTestCase { } + @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/21126") public void testCancellationOfScrollSearchesOnFollowupRequests() throws Exception { List plugins = initBlockFactory(); From e82a1f5cca825e99a77e3de2cdb3d0a1a09732e0 Mon Sep 17 00:00:00 2001 From: Yannick Welsch Date: Wed, 26 Oct 2016 09:24:03 +0200 Subject: [PATCH 14/19] Only allow the master to update the list of nodes in the cluster state (#21092) The cluster state on a node is updated either - by incoming cluster states that are received from the active master or - by the node itself when it notices that the master has gone. In the second case, the node adds the NO_MASTER_BLOCK and removes the current master as active master from its cluster state. In one particular case, it would also update the list of nodes, removing the master node that just failed. In the future, we want a clear separation between actions that can be executed by a master publishing a cluster state and a node locally updating its cluster state when no active master is around. --- .../java/org/elasticsearch/discovery/zen/ZenDiscovery.java | 7 +------ .../org/elasticsearch/cluster/MinimumMasterNodesIT.java | 4 +++- .../discovery/DiscoveryWithServiceDisruptionsIT.java | 6 +++++- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java b/core/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java index ba76c9ab7d2..46f3a6fb315 100644 --- a/core/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java +++ b/core/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java @@ -683,15 +683,10 @@ public class ZenDiscovery extends AbstractLifecycleComponent implements Discover return currentState; } - DiscoveryNodes discoveryNodes = DiscoveryNodes.builder(currentState.nodes()) - // make sure the old master node, which has failed, is not part of the nodes we publish - .remove(masterNode) - .masterNodeId(null).build(); - // flush any pending cluster states from old master, so it will not be set as master again publishClusterState.pendingStatesQueue().failAllStatesAndClear(new ElasticsearchException("master left [{}]", reason)); - return rejoin(ClusterState.builder(currentState).nodes(discoveryNodes).build(), "master left (reason = " + reason + ")"); + return rejoin(currentState, "master left (reason = " + reason + ")"); } @Override diff --git a/core/src/test/java/org/elasticsearch/cluster/MinimumMasterNodesIT.java b/core/src/test/java/org/elasticsearch/cluster/MinimumMasterNodesIT.java index 83472a1edc4..fd68e484062 100644 --- a/core/src/test/java/org/elasticsearch/cluster/MinimumMasterNodesIT.java +++ b/core/src/test/java/org/elasticsearch/cluster/MinimumMasterNodesIT.java @@ -132,7 +132,9 @@ public class MinimumMasterNodesIT extends ESIntegTestCase { }); state = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState(); assertThat(state.blocks().hasGlobalBlock(DiscoverySettings.NO_MASTER_BLOCK_ID), equalTo(true)); - assertThat(state.nodes().getSize(), equalTo(1)); // verify that we still see the local node in the cluster state + // verify that both nodes are still in the cluster state but there is no master + assertThat(state.nodes().getSize(), equalTo(2)); + assertThat(state.nodes().getMasterNode(), equalTo(null)); logger.info("--> starting the previous master node again..."); internalCluster().startNode(settings); diff --git a/core/src/test/java/org/elasticsearch/discovery/DiscoveryWithServiceDisruptionsIT.java b/core/src/test/java/org/elasticsearch/discovery/DiscoveryWithServiceDisruptionsIT.java index 5e40e529dae..2ea675ab3f7 100644 --- a/core/src/test/java/org/elasticsearch/discovery/DiscoveryWithServiceDisruptionsIT.java +++ b/core/src/test/java/org/elasticsearch/discovery/DiscoveryWithServiceDisruptionsIT.java @@ -993,7 +993,11 @@ public class DiscoveryWithServiceDisruptionsIT extends ESIntegTestCase { String isolatedNode = randomBoolean() ? masterNode : nonMasterNode; TwoPartitions partitions = isolateNode(isolatedNode); - NetworkDisruption networkDisruption = addRandomDisruptionType(partitions); + // we cannot use the NetworkUnresponsive disruption type here as it will swallow the "shard failed" request, calling neither + // onSuccess nor onFailure on the provided listener. + NetworkLinkDisruptionType disruptionType = new NetworkDisconnect(); + NetworkDisruption networkDisruption = new NetworkDisruption(partitions, disruptionType); + setDisruptionScheme(networkDisruption); networkDisruption.startDisrupting(); service.localShardFailed(failedShard, "simulated", new CorruptIndexException("simulated", (String) null), new From aaf347732720187ea3fd4e5dd8661f1434a87249 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20B=C3=BCscher?= Date: Wed, 26 Oct 2016 15:24:12 +0200 Subject: [PATCH 15/19] Remove checkstyle LineLenght check suppression from 23 more classes --- .../resources/checkstyle_suppressions.xml | 23 ------------------- 1 file changed, 23 deletions(-) diff --git a/buildSrc/src/main/resources/checkstyle_suppressions.xml b/buildSrc/src/main/resources/checkstyle_suppressions.xml index 040047b6b33..c461a53fd88 100644 --- a/buildSrc/src/main/resources/checkstyle_suppressions.xml +++ b/buildSrc/src/main/resources/checkstyle_suppressions.xml @@ -63,8 +63,6 @@ - - @@ -116,8 +114,6 @@ - - @@ -228,7 +224,6 @@ - @@ -243,7 +238,6 @@ - @@ -256,7 +250,6 @@ - @@ -307,13 +300,10 @@ - - - @@ -379,7 +369,6 @@ - @@ -410,7 +399,6 @@ - @@ -454,7 +442,6 @@ - @@ -473,7 +460,6 @@ - @@ -544,8 +530,6 @@ - - @@ -586,7 +570,6 @@ - @@ -780,7 +763,6 @@ - @@ -808,10 +790,8 @@ - - @@ -842,7 +822,6 @@ - @@ -870,7 +849,6 @@ - @@ -969,7 +947,6 @@ - From c88452dc80f8ec32aecc7952e41b4fb303f69bee Mon Sep 17 00:00:00 2001 From: Ali Beyad Date: Wed, 26 Oct 2016 10:04:50 -0400 Subject: [PATCH 16/19] Abort snapshots on a node that leaves the cluster (#21084) Previously, if a node left the cluster (for example, due to a long GC), during a snapshot, the master node would mark the snapshot as failed, but the node itself could continue snapshotting the data on its shards to the repository. If the node rejoins the cluster, the master may assign it to hold the replica shard (where it held the primary before getting kicked off the cluster). The initialization of the replica shard would repeatedly fail with a ShardLockObtainFailedException until the snapshot thread finally finishes and relinquishes the lock on the Store. This commit resolves the situation by ensuring that when a shard is removed from a node (such as when a node rejoins the cluster and realizes it no longer holds the active shard copy), any snapshotting of the removed shards is aborted. In the scenario above, when the node rejoins the cluster, it will see in the cluster state that the node no longer holds the primary shard, so IndicesClusterStateService will remove the shard, thereby causing any snapshots of that shard to be aborted. Closes #20876 --- .../cluster/SnapshotsInProgress.java | 32 ++++---- .../cluster/node/DiscoveryNodes.java | 5 +- .../org/elasticsearch/index/IndexService.java | 6 +- .../snapshots/IndexShardSnapshotStatus.java | 4 +- .../cluster/IndicesClusterStateService.java | 11 ++- .../snapshots/SnapshotShardsService.java | 74 ++++++++++++------- .../snapshots/SnapshotsService.java | 4 +- ...ClusterStateServiceRandomUpdatesTests.java | 2 +- .../SharedClusterSnapshotRestoreIT.java | 65 ++++++++++++++++ 9 files changed, 146 insertions(+), 57 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/cluster/SnapshotsInProgress.java b/core/src/main/java/org/elasticsearch/cluster/SnapshotsInProgress.java index 70880373530..6df5f85987d 100644 --- a/core/src/main/java/org/elasticsearch/cluster/SnapshotsInProgress.java +++ b/core/src/main/java/org/elasticsearch/cluster/SnapshotsInProgress.java @@ -210,12 +210,9 @@ public class SnapshotsInProgress extends AbstractDiffable implements Cus public static class ShardSnapshotStatus { - private State state; - private String nodeId; - private String reason; - - private ShardSnapshotStatus() { - } + private final State state; + private final String nodeId; + private final String reason; public ShardSnapshotStatus(String nodeId) { this(nodeId, State.INIT); @@ -231,6 +228,12 @@ public class SnapshotsInProgress extends AbstractDiffable implements Cus this.reason = reason; } + public ShardSnapshotStatus(StreamInput in) throws IOException { + nodeId = in.readOptionalString(); + state = State.fromValue(in.readByte()); + reason = in.readOptionalString(); + } + public State state() { return state; } @@ -243,18 +246,6 @@ public class SnapshotsInProgress extends AbstractDiffable implements Cus return reason; } - public static ShardSnapshotStatus readShardSnapshotStatus(StreamInput in) throws IOException { - ShardSnapshotStatus shardSnapshotStatus = new ShardSnapshotStatus(); - shardSnapshotStatus.readFrom(in); - return shardSnapshotStatus; - } - - public void readFrom(StreamInput in) throws IOException { - nodeId = in.readOptionalString(); - state = State.fromValue(in.readByte()); - reason = in.readOptionalString(); - } - public void writeTo(StreamOutput out) throws IOException { out.writeOptionalString(nodeId); out.writeByte(state.value); @@ -282,6 +273,11 @@ public class SnapshotsInProgress extends AbstractDiffable implements Cus result = 31 * result + (reason != null ? reason.hashCode() : 0); return result; } + + @Override + public String toString() { + return "ShardSnapshotStatus[state=" + state + ", nodeId=" + nodeId + ", reason=" + reason + "]"; + } } public enum State { diff --git a/core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java b/core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java index 9d0edf7b910..f3a8932f53c 100644 --- a/core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java +++ b/core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java @@ -26,6 +26,7 @@ import org.elasticsearch.Version; import org.elasticsearch.cluster.AbstractDiffable; import org.elasticsearch.common.Booleans; import org.elasticsearch.common.Nullable; +import org.elasticsearch.common.Strings; import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; @@ -399,9 +400,7 @@ public class DiscoveryNodes extends AbstractDiffable implements public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{"); - for (DiscoveryNode node : this) { - sb.append(node).append(','); - } + sb.append(Strings.collectionToDelimitedString(this, ",")); sb.append("}"); return sb.toString(); } diff --git a/core/src/main/java/org/elasticsearch/index/IndexService.java b/core/src/main/java/org/elasticsearch/index/IndexService.java index ee1f1d1c976..ffcc7648293 100644 --- a/core/src/main/java/org/elasticsearch/index/IndexService.java +++ b/core/src/main/java/org/elasticsearch/index/IndexService.java @@ -411,7 +411,11 @@ public class IndexService extends AbstractIndexComponent implements IndicesClust } } finally { try { - store.close(); + if (store != null) { + store.close(); + } else { + logger.trace("[{}] store not initialized prior to closing shard, nothing to close", shardId); + } } catch (Exception e) { logger.warn( (Supplier) () -> new ParameterizedMessage( diff --git a/core/src/main/java/org/elasticsearch/index/snapshots/IndexShardSnapshotStatus.java b/core/src/main/java/org/elasticsearch/index/snapshots/IndexShardSnapshotStatus.java index 51c8bcf5d7e..644caa7520b 100644 --- a/core/src/main/java/org/elasticsearch/index/snapshots/IndexShardSnapshotStatus.java +++ b/core/src/main/java/org/elasticsearch/index/snapshots/IndexShardSnapshotStatus.java @@ -27,7 +27,7 @@ public class IndexShardSnapshotStatus { /** * Snapshot stage */ - public static enum Stage { + public enum Stage { /** * Snapshot hasn't started yet */ @@ -66,7 +66,7 @@ public class IndexShardSnapshotStatus { private long indexVersion; - private boolean aborted; + private volatile boolean aborted; private String failure; diff --git a/core/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java b/core/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java index b55074f592d..1fb360ccfd5 100644 --- a/core/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java +++ b/core/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java @@ -69,6 +69,7 @@ import org.elasticsearch.indices.recovery.RecoveryState; import org.elasticsearch.repositories.RepositoriesService; import org.elasticsearch.search.SearchService; import org.elasticsearch.snapshots.RestoreService; +import org.elasticsearch.snapshots.SnapshotShardsService; import org.elasticsearch.threadpool.ThreadPool; import java.io.IOException; @@ -113,10 +114,11 @@ public class IndicesClusterStateService extends AbstractLifecycleComponent imple NodeMappingRefreshAction nodeMappingRefreshAction, RepositoriesService repositoriesService, RestoreService restoreService, SearchService searchService, SyncedFlushService syncedFlushService, - PeerRecoverySourceService peerRecoverySourceService) { + PeerRecoverySourceService peerRecoverySourceService, SnapshotShardsService snapshotShardsService) { this(settings, (AllocatedIndices>) indicesService, clusterService, threadPool, recoveryTargetService, shardStateAction, - nodeMappingRefreshAction, repositoriesService, restoreService, searchService, syncedFlushService, peerRecoverySourceService); + nodeMappingRefreshAction, repositoriesService, restoreService, searchService, syncedFlushService, peerRecoverySourceService, + snapshotShardsService); } // for tests @@ -128,9 +130,10 @@ public class IndicesClusterStateService extends AbstractLifecycleComponent imple NodeMappingRefreshAction nodeMappingRefreshAction, RepositoriesService repositoriesService, RestoreService restoreService, SearchService searchService, SyncedFlushService syncedFlushService, - PeerRecoverySourceService peerRecoverySourceService) { + PeerRecoverySourceService peerRecoverySourceService, SnapshotShardsService snapshotShardsService) { super(settings); - this.buildInIndexListener = Arrays.asList(peerRecoverySourceService, recoveryTargetService, searchService, syncedFlushService); + this.buildInIndexListener = Arrays.asList(peerRecoverySourceService, recoveryTargetService, searchService, syncedFlushService, + snapshotShardsService); this.indicesService = indicesService; this.clusterService = clusterService; this.threadPool = threadPool; diff --git a/core/src/main/java/org/elasticsearch/snapshots/SnapshotShardsService.java b/core/src/main/java/org/elasticsearch/snapshots/SnapshotShardsService.java index 1f7a4ee4fd6..d939236732e 100644 --- a/core/src/main/java/org/elasticsearch/snapshots/SnapshotShardsService.java +++ b/core/src/main/java/org/elasticsearch/snapshots/SnapshotShardsService.java @@ -29,8 +29,10 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.ClusterStateListener; import org.elasticsearch.cluster.ClusterStateUpdateTask; import org.elasticsearch.cluster.SnapshotsInProgress; +import org.elasticsearch.cluster.SnapshotsInProgress.ShardSnapshotStatus; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.service.ClusterService; +import org.elasticsearch.common.Nullable; import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.component.AbstractLifecycleComponent; import org.elasticsearch.common.inject.Inject; @@ -42,11 +44,13 @@ import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.util.concurrent.AbstractRunnable; import org.elasticsearch.common.util.concurrent.ConcurrentCollections; import org.elasticsearch.index.engine.SnapshotFailedEngineException; +import org.elasticsearch.index.shard.IndexEventListener; import org.elasticsearch.index.shard.IndexShard; import org.elasticsearch.index.shard.IndexShardState; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.snapshots.IndexShardSnapshotFailedException; import org.elasticsearch.index.snapshots.IndexShardSnapshotStatus; +import org.elasticsearch.index.snapshots.IndexShardSnapshotStatus.Stage; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.repositories.IndexId; import org.elasticsearch.repositories.Repository; @@ -80,7 +84,7 @@ import static org.elasticsearch.cluster.SnapshotsInProgress.completed; * This service runs on data and master nodes and controls currently snapshotted shards on these nodes. It is responsible for * starting and stopping shard level snapshots */ -public class SnapshotShardsService extends AbstractLifecycleComponent implements ClusterStateListener { +public class SnapshotShardsService extends AbstractLifecycleComponent implements ClusterStateListener, IndexEventListener { public static final String UPDATE_SNAPSHOT_ACTION_NAME = "internal:cluster/snapshot/update_snapshot"; @@ -156,12 +160,8 @@ public class SnapshotShardsService extends AbstractLifecycleComponent implements SnapshotsInProgress prev = event.previousState().custom(SnapshotsInProgress.TYPE); SnapshotsInProgress curr = event.state().custom(SnapshotsInProgress.TYPE); - if (prev == null) { - if (curr != null) { - processIndexShardSnapshots(event); - } - } else if (prev.equals(curr) == false) { - processIndexShardSnapshots(event); + if ((prev == null && curr != null) || (prev != null && prev.equals(curr) == false)) { + processIndexShardSnapshots(event); } String masterNodeId = event.state().nodes().getMasterNodeId(); if (masterNodeId != null && masterNodeId.equals(event.previousState().nodes().getMasterNodeId()) == false) { @@ -173,6 +173,18 @@ public class SnapshotShardsService extends AbstractLifecycleComponent implements } } + @Override + public void beforeIndexShardClosed(ShardId shardId, @Nullable IndexShard indexShard, Settings indexSettings) { + // abort any snapshots occurring on the soon-to-be closed shard + Map snapshotShardsMap = shardSnapshots; + for (Map.Entry snapshotShards : snapshotShardsMap.entrySet()) { + Map shards = snapshotShards.getValue().shards; + if (shards.containsKey(shardId)) { + logger.debug("[{}] shard closing, abort snapshotting for snapshot [{}]", shardId, snapshotShards.getKey().getSnapshotId()); + shards.get(shardId).abort(); + } + } + } /** * Returns status of shards that are snapshotted on the node and belong to the given snapshot @@ -205,6 +217,16 @@ public class SnapshotShardsService extends AbstractLifecycleComponent implements final Snapshot snapshot = entry.getKey(); if (snapshotsInProgress != null && snapshotsInProgress.snapshot(snapshot) != null) { survivors.put(entry.getKey(), entry.getValue()); + } else { + // abort any running snapshots of shards for the removed entry; + // this could happen if for some reason the cluster state update for aborting + // running shards is missed, then the snapshot is removed is a subsequent cluster + // state update, which is being processed here + for (IndexShardSnapshotStatus snapshotStatus : entry.getValue().shards.values()) { + if (snapshotStatus.stage() == Stage.INIT || snapshotStatus.stage() == Stage.STARTED) { + snapshotStatus.abort(); + } + } } } @@ -221,7 +243,7 @@ public class SnapshotShardsService extends AbstractLifecycleComponent implements if (entry.state() == SnapshotsInProgress.State.STARTED) { Map startedShards = new HashMap<>(); SnapshotShards snapshotShards = shardSnapshots.get(entry.snapshot()); - for (ObjectObjectCursor shard : entry.shards()) { + for (ObjectObjectCursor shard : entry.shards()) { // Add all new shards to start processing on if (localNodeId.equals(shard.value.nodeId())) { if (shard.value.state() == SnapshotsInProgress.State.INIT && (snapshotShards == null || !snapshotShards.shards.containsKey(shard.key))) { @@ -249,7 +271,7 @@ public class SnapshotShardsService extends AbstractLifecycleComponent implements // Abort all running shards for this snapshot SnapshotShards snapshotShards = shardSnapshots.get(entry.snapshot()); if (snapshotShards != null) { - for (ObjectObjectCursor shard : entry.shards()) { + for (ObjectObjectCursor shard : entry.shards()) { IndexShardSnapshotStatus snapshotStatus = snapshotShards.shards.get(shard.key); if (snapshotStatus != null) { switch (snapshotStatus.stage()) { @@ -263,12 +285,12 @@ public class SnapshotShardsService extends AbstractLifecycleComponent implements case DONE: logger.debug("[{}] trying to cancel snapshot on the shard [{}] that is already done, updating status on the master", entry.snapshot(), shard.key); updateIndexShardSnapshotStatus(entry.snapshot(), shard.key, - new SnapshotsInProgress.ShardSnapshotStatus(event.state().nodes().getLocalNodeId(), SnapshotsInProgress.State.SUCCESS)); + new ShardSnapshotStatus(event.state().nodes().getLocalNodeId(), SnapshotsInProgress.State.SUCCESS)); break; case FAILURE: logger.debug("[{}] trying to cancel snapshot on the shard [{}] that has already failed, updating status on the master", entry.snapshot(), shard.key); updateIndexShardSnapshotStatus(entry.snapshot(), shard.key, - new SnapshotsInProgress.ShardSnapshotStatus(event.state().nodes().getLocalNodeId(), SnapshotsInProgress.State.FAILED, snapshotStatus.failure())); + new ShardSnapshotStatus(event.state().nodes().getLocalNodeId(), SnapshotsInProgress.State.FAILED, snapshotStatus.failure())); break; default: throw new IllegalStateException("Unknown snapshot shard stage " + snapshotStatus.stage()); @@ -309,18 +331,18 @@ public class SnapshotShardsService extends AbstractLifecycleComponent implements @Override public void doRun() { snapshot(indexShard, entry.getKey(), indexId, shardEntry.getValue()); - updateIndexShardSnapshotStatus(entry.getKey(), shardId, new SnapshotsInProgress.ShardSnapshotStatus(localNodeId, SnapshotsInProgress.State.SUCCESS)); + updateIndexShardSnapshotStatus(entry.getKey(), shardId, new ShardSnapshotStatus(localNodeId, SnapshotsInProgress.State.SUCCESS)); } @Override public void onFailure(Exception e) { logger.warn((Supplier) () -> new ParameterizedMessage("[{}] [{}] failed to create snapshot", shardId, entry.getKey()), e); - updateIndexShardSnapshotStatus(entry.getKey(), shardId, new SnapshotsInProgress.ShardSnapshotStatus(localNodeId, SnapshotsInProgress.State.FAILED, ExceptionsHelper.detailedMessage(e))); + updateIndexShardSnapshotStatus(entry.getKey(), shardId, new ShardSnapshotStatus(localNodeId, SnapshotsInProgress.State.FAILED, ExceptionsHelper.detailedMessage(e))); } }); } catch (Exception e) { - updateIndexShardSnapshotStatus(entry.getKey(), shardId, new SnapshotsInProgress.ShardSnapshotStatus(localNodeId, SnapshotsInProgress.State.FAILED, ExceptionsHelper.detailedMessage(e))); + updateIndexShardSnapshotStatus(entry.getKey(), shardId, new ShardSnapshotStatus(localNodeId, SnapshotsInProgress.State.FAILED, ExceptionsHelper.detailedMessage(e))); } } } @@ -383,23 +405,23 @@ public class SnapshotShardsService extends AbstractLifecycleComponent implements if (snapshot.state() == SnapshotsInProgress.State.STARTED || snapshot.state() == SnapshotsInProgress.State.ABORTED) { Map localShards = currentSnapshotShards(snapshot.snapshot()); if (localShards != null) { - ImmutableOpenMap masterShards = snapshot.shards(); + ImmutableOpenMap masterShards = snapshot.shards(); for(Map.Entry localShard : localShards.entrySet()) { ShardId shardId = localShard.getKey(); IndexShardSnapshotStatus localShardStatus = localShard.getValue(); - SnapshotsInProgress.ShardSnapshotStatus masterShard = masterShards.get(shardId); + ShardSnapshotStatus masterShard = masterShards.get(shardId); if (masterShard != null && masterShard.state().completed() == false) { // Master knows about the shard and thinks it has not completed - if (localShardStatus.stage() == IndexShardSnapshotStatus.Stage.DONE) { + if (localShardStatus.stage() == Stage.DONE) { // but we think the shard is done - we need to make new master know that the shard is done logger.debug("[{}] new master thinks the shard [{}] is not completed but the shard is done locally, updating status on the master", snapshot.snapshot(), shardId); updateIndexShardSnapshotStatus(snapshot.snapshot(), shardId, - new SnapshotsInProgress.ShardSnapshotStatus(event.state().nodes().getLocalNodeId(), SnapshotsInProgress.State.SUCCESS)); - } else if (localShard.getValue().stage() == IndexShardSnapshotStatus.Stage.FAILURE) { + new ShardSnapshotStatus(event.state().nodes().getLocalNodeId(), SnapshotsInProgress.State.SUCCESS)); + } else if (localShard.getValue().stage() == Stage.FAILURE) { // but we think the shard failed - we need to make new master know that the shard failed logger.debug("[{}] new master thinks the shard [{}] is not completed but the shard failed locally, updating status on master", snapshot.snapshot(), shardId); updateIndexShardSnapshotStatus(snapshot.snapshot(), shardId, - new SnapshotsInProgress.ShardSnapshotStatus(event.state().nodes().getLocalNodeId(), SnapshotsInProgress.State.FAILED, localShardStatus.failure())); + new ShardSnapshotStatus(event.state().nodes().getLocalNodeId(), SnapshotsInProgress.State.FAILED, localShardStatus.failure())); } } @@ -427,7 +449,7 @@ public class SnapshotShardsService extends AbstractLifecycleComponent implements public static class UpdateIndexShardSnapshotStatusRequest extends TransportRequest { private Snapshot snapshot; private ShardId shardId; - private SnapshotsInProgress.ShardSnapshotStatus status; + private ShardSnapshotStatus status; private volatile boolean processed; // state field, no need to serialize @@ -435,7 +457,7 @@ public class SnapshotShardsService extends AbstractLifecycleComponent implements } - public UpdateIndexShardSnapshotStatusRequest(Snapshot snapshot, ShardId shardId, SnapshotsInProgress.ShardSnapshotStatus status) { + public UpdateIndexShardSnapshotStatusRequest(Snapshot snapshot, ShardId shardId, ShardSnapshotStatus status) { this.snapshot = snapshot; this.shardId = shardId; this.status = status; @@ -446,7 +468,7 @@ public class SnapshotShardsService extends AbstractLifecycleComponent implements super.readFrom(in); snapshot = new Snapshot(in); shardId = ShardId.readShardId(in); - status = SnapshotsInProgress.ShardSnapshotStatus.readShardSnapshotStatus(in); + status = new ShardSnapshotStatus(in); } @Override @@ -465,7 +487,7 @@ public class SnapshotShardsService extends AbstractLifecycleComponent implements return shardId; } - public SnapshotsInProgress.ShardSnapshotStatus status() { + public ShardSnapshotStatus status() { return status; } @@ -486,7 +508,7 @@ public class SnapshotShardsService extends AbstractLifecycleComponent implements /** * Updates the shard status */ - public void updateIndexShardSnapshotStatus(Snapshot snapshot, ShardId shardId, SnapshotsInProgress.ShardSnapshotStatus status) { + public void updateIndexShardSnapshotStatus(Snapshot snapshot, ShardId shardId, ShardSnapshotStatus status) { UpdateIndexShardSnapshotStatusRequest request = new UpdateIndexShardSnapshotStatusRequest(snapshot, shardId, status); try { if (clusterService.state().nodes().isLocalNodeElectedMaster()) { @@ -533,7 +555,7 @@ public class SnapshotShardsService extends AbstractLifecycleComponent implements int changedCount = 0; final List entries = new ArrayList<>(); for (SnapshotsInProgress.Entry entry : snapshots.entries()) { - ImmutableOpenMap.Builder shards = ImmutableOpenMap.builder(); + ImmutableOpenMap.Builder shards = ImmutableOpenMap.builder(); boolean updated = false; for (int i = 0; i < batchSize; i++) { diff --git a/core/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java b/core/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java index ea8deea5661..f5ef5f111df 100644 --- a/core/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java +++ b/core/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java @@ -793,12 +793,12 @@ public class SnapshotsService extends AbstractLifecycleComponent implements Clus } private boolean removedNodesCleanupNeeded(ClusterChangedEvent event) { - // Check if we just became the master - boolean newMaster = !event.previousState().nodes().isLocalNodeElectedMaster(); SnapshotsInProgress snapshotsInProgress = event.state().custom(SnapshotsInProgress.TYPE); if (snapshotsInProgress == null) { return false; } + // Check if we just became the master + boolean newMaster = !event.previousState().nodes().isLocalNodeElectedMaster(); for (SnapshotsInProgress.Entry snapshot : snapshotsInProgress.entries()) { if (newMaster && (snapshot.state() == State.SUCCESS || snapshot.state() == State.INIT)) { // We just replaced old master and snapshots in intermediate states needs to be cleaned diff --git a/core/src/test/java/org/elasticsearch/indices/cluster/IndicesClusterStateServiceRandomUpdatesTests.java b/core/src/test/java/org/elasticsearch/indices/cluster/IndicesClusterStateServiceRandomUpdatesTests.java index 7a4753725ad..67a82d93c54 100644 --- a/core/src/test/java/org/elasticsearch/indices/cluster/IndicesClusterStateServiceRandomUpdatesTests.java +++ b/core/src/test/java/org/elasticsearch/indices/cluster/IndicesClusterStateServiceRandomUpdatesTests.java @@ -376,7 +376,7 @@ public class IndicesClusterStateServiceRandomUpdatesTests extends AbstractIndice transportService, null, clusterService); final ShardStateAction shardStateAction = mock(ShardStateAction.class); return new IndicesClusterStateService(settings, indicesService, clusterService, - threadPool, recoveryTargetService, shardStateAction, null, repositoriesService, null, null, null, null); + threadPool, recoveryTargetService, shardStateAction, null, repositoriesService, null, null, null, null, null); } private class RecordingIndicesService extends MockIndicesService { diff --git a/core/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java b/core/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java index bf69f6016de..b7ce99e6ea3 100644 --- a/core/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java +++ b/core/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java @@ -51,6 +51,7 @@ import org.elasticsearch.cluster.block.ClusterBlocks; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.MappingMetaData; import org.elasticsearch.cluster.metadata.MetaDataIndexStateService; +import org.elasticsearch.cluster.routing.IndexRoutingTable; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.Priority; import org.elasticsearch.common.collect.ImmutableOpenMap; @@ -58,8 +59,10 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeUnit; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.index.IndexService; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.store.IndexStore; +import org.elasticsearch.indices.IndicesService; import org.elasticsearch.indices.InvalidIndexNameException; import org.elasticsearch.repositories.IndexId; import org.elasticsearch.repositories.RepositoriesService; @@ -2490,4 +2493,66 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas waitForCompletion(repositoryName, inProgressSnapshot, TimeValue.timeValueSeconds(60)); } + /** + * This test ensures that when a shard is removed from a node (perhaps due to the node + * leaving the cluster, then returning), all snapshotting of that shard is aborted, so + * all Store references held onto by the snapshot are released. + * + * See https://github.com/elastic/elasticsearch/issues/20876 + */ + public void testSnapshotCanceledOnRemovedShard() throws Exception { + final int numPrimaries = 1; + final int numReplicas = 1; + final int numDocs = 100; + final String repo = "test-repo"; + final String index = "test-idx"; + final String snapshot = "test-snap"; + + assertAcked(prepareCreate(index, 1, + Settings.builder().put("number_of_shards", numPrimaries).put("number_of_replicas", numReplicas))); + + logger.info("--> indexing some data"); + for (int i = 0; i < numDocs; i++) { + index(index, "doc", Integer.toString(i), "foo", "bar" + i); + } + refresh(); + + logger.info("--> creating repository"); + PutRepositoryResponse putRepositoryResponse = + client().admin().cluster().preparePutRepository(repo).setType("mock").setSettings(Settings.builder() + .put("location", randomRepoPath()) + .put("random", randomAsciiOfLength(10)) + .put("wait_after_unblock", 200) + ).get(); + assertTrue(putRepositoryResponse.isAcknowledged()); + + String blockedNode = blockNodeWithIndex(repo, index); + + logger.info("--> snapshot"); + client().admin().cluster().prepareCreateSnapshot(repo, snapshot) + .setWaitForCompletion(false) + .execute(); + + logger.info("--> waiting for block to kick in on node [{}]", blockedNode); + waitForBlock(blockedNode, repo, TimeValue.timeValueSeconds(10)); + + logger.info("--> removing primary shard that is being snapshotted"); + ClusterState clusterState = internalCluster().clusterService(internalCluster().getMasterName()).state(); + IndexRoutingTable indexRoutingTable = clusterState.getRoutingTable().index(index); + String nodeWithPrimary = clusterState.nodes().get(indexRoutingTable.shard(0).primaryShard().currentNodeId()).getName(); + assertNotNull("should be at least one node with a primary shard", nodeWithPrimary); + IndicesService indicesService = internalCluster().getInstance(IndicesService.class, nodeWithPrimary); + IndexService indexService = indicesService.indexService(resolveIndex(index)); + indexService.removeShard(0, "simulate node removal"); + + logger.info("--> unblocking blocked node [{}]", blockedNode); + unblockNode(repo, blockedNode); + + logger.info("--> ensuring snapshot is aborted and the aborted shard was marked as failed"); + SnapshotInfo snapshotInfo = waitForCompletion(repo, snapshot, TimeValue.timeValueSeconds(10)); + assertEquals(1, snapshotInfo.shardFailures().size()); + assertEquals(0, snapshotInfo.shardFailures().get(0).shardId()); + assertEquals("IndexShardSnapshotFailedException[Aborted]", snapshotInfo.shardFailures().get(0).reason()); + } + } From 512a77a633831f0513a47df1555f9759f4fb3d3f Mon Sep 17 00:00:00 2001 From: Jack Conradson Date: Wed, 26 Oct 2016 10:21:22 -0700 Subject: [PATCH 17/19] Refactor ScriptType to be a top-level class. --- .../action/update/UpdateRequest.java | 11 ++- .../ingest/InternalTemplateService.java | 3 +- .../elasticsearch/script/CompiledScript.java | 6 +- .../java/org/elasticsearch/script/Script.java | 1 - .../script/ScriptContextRegistry.java | 6 +- .../org/elasticsearch/script/ScriptModes.java | 1 - .../elasticsearch/script/ScriptService.java | 66 -------------- .../elasticsearch/script/ScriptSettings.java | 14 +-- .../org/elasticsearch/script/ScriptType.java | 89 +++++++++++++++++++ .../phrase/PhraseSuggestionBuilder.java | 5 +- .../action/IndicesRequestIT.java | 4 +- .../action/bulk/BulkWithUpdatesIT.java | 3 +- .../action/update/UpdateRequestTests.java | 2 +- .../elasticsearch/cluster/NoMasterNodeIT.java | 6 +- .../index/WaitUntilRefreshIT.java | 2 +- .../index/query/InnerHitBuilderTests.java | 4 +- .../query/QueryDSLDocumentationTests.java | 2 +- .../index/query/ScriptQueryBuilderTests.java | 2 +- .../FunctionScoreQueryBuilderTests.java | 4 +- .../elasticsearch/script/FileScriptTests.java | 6 +- .../elasticsearch/script/IndexLookupIT.java | 2 +- .../script/NativeScriptTests.java | 1 - .../script/ScriptContextTests.java | 10 +-- .../elasticsearch/script/ScriptFieldIT.java | 1 - .../script/ScriptModesTests.java | 1 - .../script/ScriptServiceTests.java | 1 - .../org/elasticsearch/script/ScriptTests.java | 6 +- .../search/SearchCancellationIT.java | 2 +- .../elasticsearch/search/SearchTimeoutIT.java | 3 +- .../AggregationTestScriptsPlugin.java | 3 +- .../search/aggregations/EquivalenceIT.java | 2 +- .../aggregations/bucket/DateHistogramIT.java | 2 +- .../aggregations/bucket/DateRangeIT.java | 2 +- .../aggregations/bucket/DoubleTermsIT.java | 3 +- .../aggregations/bucket/HistogramIT.java | 2 +- .../search/aggregations/bucket/IpRangeIT.java | 3 +- .../aggregations/bucket/LongTermsIT.java | 3 +- .../aggregations/bucket/MinDocCountIT.java | 4 +- .../search/aggregations/bucket/RangeIT.java | 5 +- .../SignificantTermsSignificanceScoreIT.java | 2 +- .../aggregations/bucket/StringTermsIT.java | 2 +- .../search/aggregations/metrics/AvgIT.java | 2 +- .../aggregations/metrics/CardinalityIT.java | 2 +- .../aggregations/metrics/ExtendedStatsIT.java | 2 +- .../metrics/HDRPercentileRanksIT.java | 2 +- .../metrics/HDRPercentilesIT.java | 4 +- .../search/aggregations/metrics/MaxIT.java | 4 +- .../search/aggregations/metrics/MinIT.java | 4 +- .../metrics/ScriptedMetricIT.java | 2 +- .../metrics/ScriptedMetricTests.java | 2 +- .../search/aggregations/metrics/StatsIT.java | 2 +- .../search/aggregations/metrics/SumIT.java | 2 +- .../metrics/TDigestPercentileRanksIT.java | 2 +- .../metrics/TDigestPercentilesIT.java | 2 +- .../aggregations/metrics/TopHitsIT.java | 7 +- .../aggregations/metrics/ValueCountIT.java | 2 +- .../aggregations/pipeline/BucketScriptIT.java | 3 +- .../pipeline/BucketScriptTests.java | 2 +- .../pipeline/BucketSelectorIT.java | 3 +- .../pipeline/BucketSelectorTests.java | 2 +- .../basic/TransportTwoNodesSearchIT.java | 4 +- .../search/fetch/subphase/InnerHitsIT.java | 6 +- .../search/fields/SearchFieldsIT.java | 2 +- .../functionscore/ExplainableScriptIT.java | 2 +- .../search/functionscore/FunctionScoreIT.java | 3 +- .../functionscore/RandomScoreFunctionIT.java | 2 +- .../search/geo/GeoDistanceIT.java | 2 +- .../scriptfilter/ScriptQuerySearchIT.java | 2 +- .../search/sort/AbstractSortTestCase.java | 1 + .../search/sort/ScriptSortBuilderTests.java | 2 +- .../search/sort/SimpleSortIT.java | 3 +- .../search/stats/SearchStatsIT.java | 2 +- .../update/TimestampTTLBWIT.java | 14 +-- .../update/UpdateByNativeScriptIT.java | 5 +- .../org/elasticsearch/update/UpdateIT.java | 58 ++++++------ .../ingest/common/ScriptProcessor.java | 6 +- .../script/expression/ExpressionTests.java | 10 +-- .../expression/IndexedExpressionTests.java | 5 +- .../expression/MoreExpressionTests.java | 12 +-- .../groovy/GroovyIndexedScriptTests.java | 7 +- .../script/groovy/GroovyScriptTests.java | 2 +- .../script/groovy/GroovySecurityTests.java | 4 +- .../RestRenderSearchTemplateAction.java | 4 +- .../mustache/RestSearchTemplateAction.java | 8 +- .../mustache/SearchTemplateRequest.java | 12 +-- .../SearchTemplateRequestBuilder.java | 4 +- .../script/mustache/TemplateQueryBuilder.java | 9 +- .../mustache/CustomMustacheFactoryTests.java | 2 +- .../mustache/MultiSearchTemplateIT.java | 12 +-- .../MultiSearchTemplateRequestTests.java | 8 +- .../mustache/MustacheScriptEngineTests.java | 10 +-- .../script/mustache/MustacheTests.java | 2 +- .../script/mustache/SearchTemplateIT.java | 13 ++- .../mustache/SearchTemplateRequestTests.java | 18 ++-- .../mustache/TemplateQueryBuilderTests.java | 2 +- .../painless/NeedsScoreTests.java | 2 +- .../painless/ScriptEngineTests.java | 6 +- .../painless/ScriptTestCase.java | 4 +- .../percolator/PercolatorQuerySearchIT.java | 5 +- .../reindex/RestUpdateByQueryAction.java | 20 ++--- .../index/reindex/RoundTripTests.java | 2 +- .../JavaScriptScriptEngineTests.java | 28 +++--- .../JavaScriptScriptMultiThreadedTests.java | 8 +- .../javascript/JavaScriptSecurityTests.java | 4 +- .../python/PythonScriptEngineTests.java | 20 ++--- .../PythonScriptMultiThreadedTests.java | 6 +- .../script/python/PythonSecurityTests.java | 4 +- 107 files changed, 355 insertions(+), 360 deletions(-) create mode 100644 core/src/main/java/org/elasticsearch/script/ScriptType.java diff --git a/core/src/main/java/org/elasticsearch/action/update/UpdateRequest.java b/core/src/main/java/org/elasticsearch/action/update/UpdateRequest.java index 14ef2058856..54c435da366 100644 --- a/core/src/main/java/org/elasticsearch/action/update/UpdateRequest.java +++ b/core/src/main/java/org/elasticsearch/action/update/UpdateRequest.java @@ -42,8 +42,7 @@ import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.VersionType; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService; -import org.elasticsearch.script.ScriptService.ScriptType; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.fetch.subphase.FetchSourceContext; import java.io.IOException; @@ -232,7 +231,7 @@ public class UpdateRequest extends InstanceShardOperationRequest * @deprecated Use {@link #script()} instead */ @Deprecated - public ScriptService.ScriptType scriptType() { + public ScriptType scriptType() { return this.script == null ? null : this.script.getType(); } @@ -252,7 +251,7 @@ public class UpdateRequest extends InstanceShardOperationRequest * @deprecated Use {@link #script(Script)} instead */ @Deprecated - public UpdateRequest script(String script, ScriptService.ScriptType scriptType) { + public UpdateRequest script(String script, ScriptType scriptType) { updateOrCreateScript(script, scriptType, null, null); return this; } @@ -347,7 +346,7 @@ public class UpdateRequest extends InstanceShardOperationRequest * @deprecated Use {@link #script(Script)} instead */ @Deprecated - public UpdateRequest script(String script, ScriptService.ScriptType scriptType, @Nullable Map scriptParams) { + public UpdateRequest script(String script, ScriptType scriptType, @Nullable Map scriptParams) { this.script = new Script(script, scriptType, null, scriptParams); return this; } @@ -369,7 +368,7 @@ public class UpdateRequest extends InstanceShardOperationRequest * @deprecated Use {@link #script(Script)} instead */ @Deprecated - public UpdateRequest script(String script, @Nullable String scriptLang, ScriptService.ScriptType scriptType, + public UpdateRequest script(String script, @Nullable String scriptLang, ScriptType scriptType, @Nullable Map scriptParams) { this.script = new Script(script, scriptType, scriptLang, scriptParams); return this; diff --git a/core/src/main/java/org/elasticsearch/ingest/InternalTemplateService.java b/core/src/main/java/org/elasticsearch/ingest/InternalTemplateService.java index 677be3b4b0c..a6c45b71697 100644 --- a/core/src/main/java/org/elasticsearch/ingest/InternalTemplateService.java +++ b/core/src/main/java/org/elasticsearch/ingest/InternalTemplateService.java @@ -25,6 +25,7 @@ import org.elasticsearch.script.ExecutableScript; import org.elasticsearch.script.Script; import org.elasticsearch.script.ScriptContext; import org.elasticsearch.script.ScriptService; +import org.elasticsearch.script.ScriptType; import java.util.Collections; import java.util.Map; @@ -42,7 +43,7 @@ public class InternalTemplateService implements TemplateService { int mustacheStart = template.indexOf("{{"); int mustacheEnd = template.indexOf("}}"); if (mustacheStart != -1 && mustacheEnd != -1 && mustacheStart < mustacheEnd) { - Script script = new Script(template, ScriptService.ScriptType.INLINE, "mustache", Collections.emptyMap()); + Script script = new Script(template, ScriptType.INLINE, "mustache", Collections.emptyMap()); CompiledScript compiledScript = scriptService.compile( script, ScriptContext.Standard.INGEST, diff --git a/core/src/main/java/org/elasticsearch/script/CompiledScript.java b/core/src/main/java/org/elasticsearch/script/CompiledScript.java index ec2ad4192a2..818971f0f89 100644 --- a/core/src/main/java/org/elasticsearch/script/CompiledScript.java +++ b/core/src/main/java/org/elasticsearch/script/CompiledScript.java @@ -24,7 +24,7 @@ package org.elasticsearch.script; */ public class CompiledScript { - private final ScriptService.ScriptType type; + private final ScriptType type; private final String name; private final String lang; private final Object compiled; @@ -36,7 +36,7 @@ public class CompiledScript { * @param lang The language of the script to be executed. * @param compiled The compiled script Object that is executable. */ - public CompiledScript(ScriptService.ScriptType type, String name, String lang, Object compiled) { + public CompiledScript(ScriptType type, String name, String lang, Object compiled) { this.type = type; this.name = name; this.lang = lang; @@ -47,7 +47,7 @@ public class CompiledScript { * Method to get the type of language. * @return The type of language the script was compiled in. */ - public ScriptService.ScriptType type() { + public ScriptType type() { return type; } diff --git a/core/src/main/java/org/elasticsearch/script/Script.java b/core/src/main/java/org/elasticsearch/script/Script.java index 47ecfd60ca1..cfdbf966b05 100644 --- a/core/src/main/java/org/elasticsearch/script/Script.java +++ b/core/src/main/java/org/elasticsearch/script/Script.java @@ -34,7 +34,6 @@ import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.query.QueryParseContext; -import org.elasticsearch.script.ScriptService.ScriptType; import java.io.IOException; import java.util.Map; diff --git a/core/src/main/java/org/elasticsearch/script/ScriptContextRegistry.java b/core/src/main/java/org/elasticsearch/script/ScriptContextRegistry.java index b4ed91faeba..2b7feeb8d7f 100644 --- a/core/src/main/java/org/elasticsearch/script/ScriptContextRegistry.java +++ b/core/src/main/java/org/elasticsearch/script/ScriptContextRegistry.java @@ -19,8 +19,6 @@ package org.elasticsearch.script; -import org.elasticsearch.common.settings.Settings; - import java.util.Collection; import java.util.HashMap; import java.util.HashSet; @@ -81,8 +79,8 @@ public final class ScriptContextRegistry { } private static Set reservedScriptContexts() { - Set reserved = new HashSet<>(ScriptService.ScriptType.values().length + ScriptContext.Standard.values().length); - for (ScriptService.ScriptType scriptType : ScriptService.ScriptType.values()) { + Set reserved = new HashSet<>(ScriptType.values().length + ScriptContext.Standard.values().length); + for (ScriptType scriptType : ScriptType.values()) { reserved.add(scriptType.toString()); } for (ScriptContext.Standard scriptContext : ScriptContext.Standard.values()) { diff --git a/core/src/main/java/org/elasticsearch/script/ScriptModes.java b/core/src/main/java/org/elasticsearch/script/ScriptModes.java index 46ab2a44d21..4f9651b290a 100644 --- a/core/src/main/java/org/elasticsearch/script/ScriptModes.java +++ b/core/src/main/java/org/elasticsearch/script/ScriptModes.java @@ -21,7 +21,6 @@ package org.elasticsearch.script; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.script.ScriptService.ScriptType; import java.util.Collections; import java.util.HashMap; diff --git a/core/src/main/java/org/elasticsearch/script/ScriptService.java b/core/src/main/java/org/elasticsearch/script/ScriptService.java index 2d6e07d12ee..f38a213123e 100644 --- a/core/src/main/java/org/elasticsearch/script/ScriptService.java +++ b/core/src/main/java/org/elasticsearch/script/ScriptService.java @@ -35,7 +35,6 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.ClusterStateListener; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.service.ClusterService; -import org.elasticsearch.common.ParseField; import org.elasticsearch.common.Strings; import org.elasticsearch.common.breaker.CircuitBreakingException; import org.elasticsearch.common.bytes.BytesReference; @@ -46,8 +45,6 @@ import org.elasticsearch.common.cache.RemovalNotification; import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.io.Streams; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.logging.LoggerMessageFormat; import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Setting; @@ -70,7 +67,6 @@ import java.nio.file.Path; import java.util.Collection; import java.util.Collections; import java.util.HashMap; -import java.util.Locale; import java.util.Map; import java.util.Objects; import java.util.concurrent.ConcurrentMap; @@ -632,68 +628,6 @@ public class ScriptService extends AbstractComponent implements Closeable, Clust } - /** - * The type of a script, more specifically where it gets loaded from: - * - provided dynamically at request time - * - loaded from an index - * - loaded from file - */ - public enum ScriptType { - - INLINE(0, "inline", "inline", false), - STORED(1, "id", "stored", false), - FILE(2, "file", "file", true); - - private final int val; - private final ParseField parseField; - private final String scriptType; - private final boolean defaultScriptEnabled; - - public static ScriptType readFrom(StreamInput in) throws IOException { - int scriptTypeVal = in.readVInt(); - for (ScriptType type : values()) { - if (type.val == scriptTypeVal) { - return type; - } - } - throw new IllegalArgumentException("Unexpected value read for ScriptType got [" + scriptTypeVal + "] expected one of [" - + INLINE.val + "," + FILE.val + "," + STORED.val + "]"); - } - - public static void writeTo(ScriptType scriptType, StreamOutput out) throws IOException{ - if (scriptType != null) { - out.writeVInt(scriptType.val); - } else { - out.writeVInt(INLINE.val); //Default to inline - } - } - - ScriptType(int val, String name, String scriptType, boolean defaultScriptEnabled) { - this.val = val; - this.parseField = new ParseField(name); - this.scriptType = scriptType; - this.defaultScriptEnabled = defaultScriptEnabled; - } - - public ParseField getParseField() { - return parseField; - } - - public boolean getDefaultScriptEnabled() { - return defaultScriptEnabled; - } - - public String getScriptType() { - return scriptType; - } - - @Override - public String toString() { - return name().toLowerCase(Locale.ROOT); - } - - } - private static final class CacheKey { final String lang; final String name; diff --git a/core/src/main/java/org/elasticsearch/script/ScriptSettings.java b/core/src/main/java/org/elasticsearch/script/ScriptSettings.java index 1cb2b356245..07e0deb5b71 100644 --- a/core/src/main/java/org/elasticsearch/script/ScriptSettings.java +++ b/core/src/main/java/org/elasticsearch/script/ScriptSettings.java @@ -43,11 +43,11 @@ public class ScriptSettings { @Deprecated public static final String LEGACY_SCRIPT_SETTING = "script.legacy.default_lang"; - private static final Map> SCRIPT_TYPE_SETTING_MAP; + private static final Map> SCRIPT_TYPE_SETTING_MAP; static { - Map> scriptTypeSettingMap = new HashMap<>(); - for (ScriptService.ScriptType scriptType : ScriptService.ScriptType.values()) { + Map> scriptTypeSettingMap = new HashMap<>(); + for (ScriptType scriptType : ScriptType.values()) { scriptTypeSettingMap.put(scriptType, Setting.boolSetting( ScriptModes.sourceKey(scriptType), scriptType.getDefaultScriptEnabled(), @@ -84,7 +84,7 @@ public class ScriptSettings { return scriptContextSettingMap; } - private static List> languageSettings(Map> scriptTypeSettingMap, + private static List> languageSettings(Map> scriptTypeSettingMap, Map> scriptContextSettingMap, ScriptEngineRegistry scriptEngineRegistry, ScriptContextRegistry scriptContextRegistry) { @@ -96,13 +96,13 @@ public class ScriptSettings { continue; } final String language = scriptEngineRegistry.getLanguage(scriptEngineService); - for (final ScriptService.ScriptType scriptType : ScriptService.ScriptType.values()) { + for (final ScriptType scriptType : ScriptType.values()) { // Top level, like "script.engine.groovy.inline" final boolean defaultNonFileScriptMode = scriptEngineRegistry.getDefaultInlineScriptEnableds().get(language); boolean defaultLangAndType = defaultNonFileScriptMode; // Files are treated differently because they are never default-deny - if (ScriptService.ScriptType.FILE == scriptType) { - defaultLangAndType = ScriptService.ScriptType.FILE.getDefaultScriptEnabled(); + if (ScriptType.FILE == scriptType) { + defaultLangAndType = ScriptType.FILE.getDefaultScriptEnabled(); } final boolean defaultIfNothingSet = defaultLangAndType; diff --git a/core/src/main/java/org/elasticsearch/script/ScriptType.java b/core/src/main/java/org/elasticsearch/script/ScriptType.java new file mode 100644 index 00000000000..77865daa372 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/script/ScriptType.java @@ -0,0 +1,89 @@ +/* + * 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.script; + +import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; + +import java.io.IOException; +import java.util.Locale; + +/** + * The type of a script, more specifically where it gets loaded from: + * - provided dynamically at request time + * - loaded from an index + * - loaded from file + */ +public enum ScriptType { + + INLINE(0, "inline", "inline", false), + STORED(1, "id", "stored", false), + FILE(2, "file", "file", true); + + private final int val; + private final ParseField parseField; + private final String scriptType; + private final boolean defaultScriptEnabled; + + public static ScriptType readFrom(StreamInput in) throws IOException { + int scriptTypeVal = in.readVInt(); + for (ScriptType type : values()) { + if (type.val == scriptTypeVal) { + return type; + } + } + throw new IllegalArgumentException("Unexpected value read for ScriptType got [" + scriptTypeVal + "] expected one of [" + + INLINE.val + "," + FILE.val + "," + STORED.val + "]"); + } + + public static void writeTo(ScriptType scriptType, StreamOutput out) throws IOException{ + if (scriptType != null) { + out.writeVInt(scriptType.val); + } else { + out.writeVInt(INLINE.val); //Default to inline + } + } + + ScriptType(int val, String name, String scriptType, boolean defaultScriptEnabled) { + this.val = val; + this.parseField = new ParseField(name); + this.scriptType = scriptType; + this.defaultScriptEnabled = defaultScriptEnabled; + } + + public ParseField getParseField() { + return parseField; + } + + public boolean getDefaultScriptEnabled() { + return defaultScriptEnabled; + } + + public String getScriptType() { + return scriptType; + } + + @Override + public String toString() { + return name().toLowerCase(Locale.ROOT); + } + +} diff --git a/core/src/main/java/org/elasticsearch/search/suggest/phrase/PhraseSuggestionBuilder.java b/core/src/main/java/org/elasticsearch/search/suggest/phrase/PhraseSuggestionBuilder.java index 7ec7fdda069..445924680b1 100644 --- a/core/src/main/java/org/elasticsearch/search/suggest/phrase/PhraseSuggestionBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/suggest/phrase/PhraseSuggestionBuilder.java @@ -39,11 +39,10 @@ import org.elasticsearch.index.analysis.TokenFilterFactory; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.index.query.QueryShardContext; -import org.elasticsearch.script.CompiledScript; import org.elasticsearch.script.ExecutableScript; import org.elasticsearch.script.Script; import org.elasticsearch.script.ScriptContext; -import org.elasticsearch.script.ScriptService; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.suggest.SuggestionBuilder; import org.elasticsearch.search.suggest.SuggestionSearchContext.SuggestionContext; import org.elasticsearch.search.suggest.phrase.PhraseSuggestionContext.DirectCandidateGenerator; @@ -394,7 +393,7 @@ public class PhraseSuggestionBuilder extends SuggestionBuilder randomMap = null; if (randomBoolean()) { randomMap = new HashMap<>(); diff --git a/core/src/test/java/org/elasticsearch/index/query/QueryDSLDocumentationTests.java b/core/src/test/java/org/elasticsearch/index/query/QueryDSLDocumentationTests.java index 7f1d9aebbd9..3e1e74e8ebd 100644 --- a/core/src/test/java/org/elasticsearch/index/query/QueryDSLDocumentationTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/QueryDSLDocumentationTests.java @@ -30,7 +30,7 @@ import org.elasticsearch.index.query.MoreLikeThisQueryBuilder.Item; import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder; import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder.FilterFunctionBuilder; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService.ScriptType; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.test.ESTestCase; import java.io.IOException; diff --git a/core/src/test/java/org/elasticsearch/index/query/ScriptQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/ScriptQueryBuilderTests.java index adce17c86bb..1eb2b23dceb 100644 --- a/core/src/test/java/org/elasticsearch/index/query/ScriptQueryBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/ScriptQueryBuilderTests.java @@ -23,7 +23,7 @@ import org.apache.lucene.search.Query; import org.elasticsearch.index.query.ScriptQueryBuilder.ScriptQuery; import org.elasticsearch.script.MockScriptEngine; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService.ScriptType; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.internal.SearchContext; import org.elasticsearch.test.AbstractQueryTestCase; diff --git a/core/src/test/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryBuilderTests.java index ae321438b99..88a857cccb4 100644 --- a/core/src/test/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryBuilderTests.java @@ -47,7 +47,7 @@ import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.SearchPlugin; import org.elasticsearch.script.MockScriptEngine; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.MultiValueMode; import org.elasticsearch.search.internal.SearchContext; import org.elasticsearch.test.AbstractQueryTestCase; @@ -168,7 +168,7 @@ public class FunctionScoreQueryBuilderTests extends AbstractQueryTestCase params = Collections.emptyMap(); functionBuilder = new ScriptScoreFunctionBuilder( - new Script(script, ScriptService.ScriptType.INLINE, MockScriptEngine.NAME, params)); + new Script(script, ScriptType.INLINE, MockScriptEngine.NAME, params)); break; case 3: RandomScoreFunctionBuilder randomScoreFunctionBuilder = new RandomScoreFunctionBuilderWithFixedSeed(); diff --git a/core/src/test/java/org/elasticsearch/script/FileScriptTests.java b/core/src/test/java/org/elasticsearch/script/FileScriptTests.java index 954de105a4f..58042fc768f 100644 --- a/core/src/test/java/org/elasticsearch/script/FileScriptTests.java +++ b/core/src/test/java/org/elasticsearch/script/FileScriptTests.java @@ -26,8 +26,6 @@ import org.elasticsearch.test.ESTestCase; import java.nio.file.Files; import java.nio.file.Path; import java.util.Collections; -import java.util.HashSet; -import java.util.Set; // TODO: these really should just be part of ScriptService tests, there is nothing special about them public class FileScriptTests extends ESTestCase { @@ -56,7 +54,7 @@ public class FileScriptTests extends ESTestCase { Settings settings = Settings.builder() .put("script.engine." + MockScriptEngine.NAME + ".file.aggs", "false").build(); ScriptService scriptService = makeScriptService(settings); - Script script = new Script("script1", ScriptService.ScriptType.FILE, MockScriptEngine.NAME, null); + Script script = new Script("script1", ScriptType.FILE, MockScriptEngine.NAME, null); CompiledScript compiledScript = scriptService.compile(script, ScriptContext.Standard.SEARCH, Collections.emptyMap()); assertNotNull(compiledScript); MockCompiledScript executable = (MockCompiledScript) compiledScript.compiled(); @@ -71,7 +69,7 @@ public class FileScriptTests extends ESTestCase { .put("script.engine." + MockScriptEngine.NAME + ".file.update", "false") .put("script.engine." + MockScriptEngine.NAME + ".file.ingest", "false").build(); ScriptService scriptService = makeScriptService(settings); - Script script = new Script("script1", ScriptService.ScriptType.FILE, MockScriptEngine.NAME, null); + Script script = new Script("script1", ScriptType.FILE, MockScriptEngine.NAME, null); for (ScriptContext context : ScriptContext.Standard.values()) { try { scriptService.compile(script, context, Collections.emptyMap()); diff --git a/core/src/test/java/org/elasticsearch/script/IndexLookupIT.java b/core/src/test/java/org/elasticsearch/script/IndexLookupIT.java index 7e57d41acea..f45a6c01f8e 100644 --- a/core/src/test/java/org/elasticsearch/script/IndexLookupIT.java +++ b/core/src/test/java/org/elasticsearch/script/IndexLookupIT.java @@ -48,7 +48,7 @@ import java.util.concurrent.ExecutionException; import java.util.function.Function; import static java.util.Collections.emptyList; -import static org.elasticsearch.script.ScriptService.ScriptType; + import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount; import static org.hamcrest.Matchers.containsString; diff --git a/core/src/test/java/org/elasticsearch/script/NativeScriptTests.java b/core/src/test/java/org/elasticsearch/script/NativeScriptTests.java index 1ee4c58455b..eeafbde8850 100644 --- a/core/src/test/java/org/elasticsearch/script/NativeScriptTests.java +++ b/core/src/test/java/org/elasticsearch/script/NativeScriptTests.java @@ -30,7 +30,6 @@ import org.elasticsearch.common.Nullable; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; -import org.elasticsearch.script.ScriptService.ScriptType; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.InternalSettingsPlugin; import org.elasticsearch.watcher.ResourceWatcherService; diff --git a/core/src/test/java/org/elasticsearch/script/ScriptContextTests.java b/core/src/test/java/org/elasticsearch/script/ScriptContextTests.java index 16a1c20792f..8346f7fed3e 100644 --- a/core/src/test/java/org/elasticsearch/script/ScriptContextTests.java +++ b/core/src/test/java/org/elasticsearch/script/ScriptContextTests.java @@ -25,9 +25,7 @@ import org.elasticsearch.test.ESTestCase; import java.util.Arrays; import java.util.Collections; -import java.util.HashSet; import java.util.List; -import java.util.Set; import static org.hamcrest.Matchers.containsString; @@ -58,7 +56,7 @@ public class ScriptContextTests extends ESTestCase { public void testCustomGlobalScriptContextSettings() throws Exception { ScriptService scriptService = makeScriptService(); - for (ScriptService.ScriptType scriptType : ScriptService.ScriptType.values()) { + for (ScriptType scriptType : ScriptType.values()) { try { Script script = new Script("1", scriptType, MockScriptEngine.NAME, null); scriptService.compile(script, new ScriptContext.Plugin(PLUGIN_NAME, "custom_globally_disabled_op"), Collections.emptyMap()); @@ -71,7 +69,7 @@ public class ScriptContextTests extends ESTestCase { public void testCustomScriptContextSettings() throws Exception { ScriptService scriptService = makeScriptService(); - Script script = new Script("1", ScriptService.ScriptType.INLINE, MockScriptEngine.NAME, null); + Script script = new Script("1", ScriptType.INLINE, MockScriptEngine.NAME, null); try { scriptService.compile(script, new ScriptContext.Plugin(PLUGIN_NAME, "custom_exp_disabled_op"), Collections.emptyMap()); fail("script compilation should have been rejected"); @@ -87,7 +85,7 @@ public class ScriptContextTests extends ESTestCase { public void testUnknownPluginScriptContext() throws Exception { ScriptService scriptService = makeScriptService(); - for (ScriptService.ScriptType scriptType : ScriptService.ScriptType.values()) { + for (ScriptType scriptType : ScriptType.values()) { try { Script script = new Script("1", scriptType, MockScriptEngine.NAME, null); scriptService.compile(script, new ScriptContext.Plugin(PLUGIN_NAME, "unknown"), Collections.emptyMap()); @@ -106,7 +104,7 @@ public class ScriptContextTests extends ESTestCase { } }; ScriptService scriptService = makeScriptService(); - for (ScriptService.ScriptType scriptType : ScriptService.ScriptType.values()) { + for (ScriptType scriptType : ScriptType.values()) { try { Script script = new Script("1", scriptType, MockScriptEngine.NAME, null); scriptService.compile(script, context, Collections.emptyMap()); diff --git a/core/src/test/java/org/elasticsearch/script/ScriptFieldIT.java b/core/src/test/java/org/elasticsearch/script/ScriptFieldIT.java index b15a2ab7be6..b7aeb0db47f 100644 --- a/core/src/test/java/org/elasticsearch/script/ScriptFieldIT.java +++ b/core/src/test/java/org/elasticsearch/script/ScriptFieldIT.java @@ -24,7 +24,6 @@ import org.elasticsearch.common.Nullable; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.ScriptPlugin; -import org.elasticsearch.script.ScriptService.ScriptType; import org.elasticsearch.search.SearchHit; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; diff --git a/core/src/test/java/org/elasticsearch/script/ScriptModesTests.java b/core/src/test/java/org/elasticsearch/script/ScriptModesTests.java index e4a1835ab63..a56d056cd6b 100644 --- a/core/src/test/java/org/elasticsearch/script/ScriptModesTests.java +++ b/core/src/test/java/org/elasticsearch/script/ScriptModesTests.java @@ -21,7 +21,6 @@ package org.elasticsearch.script; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.script.ScriptService.ScriptType; import org.elasticsearch.search.lookup.SearchLookup; import org.elasticsearch.test.ESTestCase; import org.junit.After; diff --git a/core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java b/core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java index bc7cb9ffb60..8ed5f4c957d 100644 --- a/core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java +++ b/core/src/test/java/org/elasticsearch/script/ScriptServiceTests.java @@ -33,7 +33,6 @@ import org.elasticsearch.common.io.Streams; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.env.Environment; -import org.elasticsearch.script.ScriptService.ScriptType; import org.elasticsearch.search.lookup.SearchLookup; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.watcher.ResourceWatcherService; diff --git a/core/src/test/java/org/elasticsearch/script/ScriptTests.java b/core/src/test/java/org/elasticsearch/script/ScriptTests.java index 316a1c8451b..c6424fdbdfe 100644 --- a/core/src/test/java/org/elasticsearch/script/ScriptTests.java +++ b/core/src/test/java/org/elasticsearch/script/ScriptTests.java @@ -66,9 +66,9 @@ public class ScriptTests extends ESTestCase { private Script createScript(XContent xContent) throws IOException { final Map params = randomBoolean() ? null : Collections.singletonMap("key", "value"); - ScriptService.ScriptType scriptType = randomFrom(ScriptService.ScriptType.values()); + ScriptType scriptType = randomFrom(ScriptType.values()); String script; - if (scriptType == ScriptService.ScriptType.INLINE) { + if (scriptType == ScriptType.INLINE) { try (XContentBuilder builder = XContentBuilder.builder(xContent)) { builder.startObject(); builder.field("field", randomAsciiOfLengthBetween(1, 5)); @@ -83,7 +83,7 @@ public class ScriptTests extends ESTestCase { scriptType, randomFrom("_lang1", "_lang2", null), params, - scriptType == ScriptService.ScriptType.INLINE ? xContent.type() : null + scriptType == ScriptType.INLINE ? xContent.type() : null ); } diff --git a/core/src/test/java/org/elasticsearch/search/SearchCancellationIT.java b/core/src/test/java/org/elasticsearch/search/SearchCancellationIT.java index 365f6df9f7c..f9b344fc264 100644 --- a/core/src/test/java/org/elasticsearch/search/SearchCancellationIT.java +++ b/core/src/test/java/org/elasticsearch/search/SearchCancellationIT.java @@ -37,7 +37,7 @@ import org.elasticsearch.script.AbstractSearchScript; import org.elasticsearch.script.ExecutableScript; import org.elasticsearch.script.NativeScriptFactory; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService.ScriptType; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.tasks.TaskInfo; import org.elasticsearch.test.ESIntegTestCase; diff --git a/core/src/test/java/org/elasticsearch/search/SearchTimeoutIT.java b/core/src/test/java/org/elasticsearch/search/SearchTimeoutIT.java index a8acb172daa..be133c37b31 100644 --- a/core/src/test/java/org/elasticsearch/search/SearchTimeoutIT.java +++ b/core/src/test/java/org/elasticsearch/search/SearchTimeoutIT.java @@ -28,8 +28,7 @@ import org.elasticsearch.script.AbstractSearchScript; import org.elasticsearch.script.ExecutableScript; import org.elasticsearch.script.NativeScriptFactory; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptModule; -import org.elasticsearch.script.ScriptService.ScriptType; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.test.ESIntegTestCase; import java.util.Collection; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/AggregationTestScriptsPlugin.java b/core/src/test/java/org/elasticsearch/search/aggregations/AggregationTestScriptsPlugin.java index 2c320288edf..b9a921c7662 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/AggregationTestScriptsPlugin.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/AggregationTestScriptsPlugin.java @@ -28,7 +28,8 @@ import java.util.Map; import java.util.function.Function; import static java.util.Collections.singletonMap; -import static org.elasticsearch.script.ScriptService.ScriptType; + +import org.elasticsearch.script.ScriptType; /** * This class contains various mocked scripts that are used in aggregations integration tests. diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/EquivalenceIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/EquivalenceIT.java index 3f03d39f116..4e1d8b6648b 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/EquivalenceIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/EquivalenceIT.java @@ -30,7 +30,7 @@ import org.elasticsearch.index.query.RangeQueryBuilder; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.MockScriptPlugin; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService.ScriptType; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.aggregations.Aggregator.SubAggCollectionMode; import org.elasticsearch.search.aggregations.bucket.filter.Filter; import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DateHistogramIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DateHistogramIT.java index 9eb21e89df1..bca3eb9c9dc 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DateHistogramIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DateHistogramIT.java @@ -28,7 +28,7 @@ import org.elasticsearch.index.query.MatchNoneQueryBuilder; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService.ScriptType; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.aggregations.bucket.DateScriptMocks.DateScriptsMockPlugin; import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; import org.elasticsearch.search.aggregations.bucket.histogram.ExtendedBounds; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DateRangeIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DateRangeIT.java index 6534658c9cd..5fe0880868a 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DateRangeIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DateRangeIT.java @@ -23,7 +23,7 @@ import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService.ScriptType; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.aggregations.bucket.DateScriptMocks.DateScriptsMockPlugin; import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; import org.elasticsearch.search.aggregations.bucket.range.Range; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DoubleTermsIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DoubleTermsIT.java index 2393512c1a3..e92485e6421 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DoubleTermsIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DoubleTermsIT.java @@ -27,10 +27,9 @@ import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.ScoreAccessor; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService.ScriptType; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.aggregations.AggregationTestScriptsPlugin; import org.elasticsearch.search.aggregations.Aggregator.SubAggCollectionMode; -import org.elasticsearch.search.aggregations.bucket.LongTermsIT.CustomScriptPlugin; import org.elasticsearch.search.aggregations.bucket.filter.Filter; import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; import org.elasticsearch.search.aggregations.bucket.terms.Terms; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/HistogramIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/HistogramIT.java index 0c4de629c6e..7e7815de54f 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/HistogramIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/HistogramIT.java @@ -26,7 +26,7 @@ import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.MockScriptPlugin; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService.ScriptType; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.aggregations.bucket.filter.Filter; import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; import org.elasticsearch.search.aggregations.bucket.histogram.Histogram.Bucket; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/IpRangeIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/IpRangeIT.java index d9f2ed7c365..7e7b11c8591 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/IpRangeIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/IpRangeIT.java @@ -37,8 +37,7 @@ import org.elasticsearch.script.AbstractSearchScript; import org.elasticsearch.script.ExecutableScript; import org.elasticsearch.script.NativeScriptFactory; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptModule; -import org.elasticsearch.script.ScriptService.ScriptType; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.aggregations.AggregationBuilders; import org.elasticsearch.search.aggregations.bucket.range.Range; import org.elasticsearch.test.ESIntegTestCase; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/LongTermsIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/LongTermsIT.java index 635b1635cc2..b97773311c6 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/LongTermsIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/LongTermsIT.java @@ -26,10 +26,9 @@ import org.elasticsearch.index.fielddata.ScriptDocValues; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService.ScriptType; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.aggregations.AggregationTestScriptsPlugin; import org.elasticsearch.search.aggregations.Aggregator.SubAggCollectionMode; -import org.elasticsearch.search.aggregations.bucket.StringTermsIT.CustomScriptPlugin; import org.elasticsearch.search.aggregations.bucket.filter.Filter; import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; import org.elasticsearch.search.aggregations.bucket.terms.Terms; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/MinDocCountIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/MinDocCountIT.java index 012df7bfbff..91885d5f5a6 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/MinDocCountIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/MinDocCountIT.java @@ -29,7 +29,7 @@ import org.elasticsearch.index.fielddata.ScriptDocValues; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.plugins.Plugin; -import org.elasticsearch.script.ScriptService; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.aggregations.AggregationTestScriptsPlugin; import org.elasticsearch.search.aggregations.Aggregator.SubAggCollectionMode; import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; @@ -151,7 +151,7 @@ public class MinDocCountIT extends AbstractTermsTestCase { YES { @Override TermsAggregationBuilder apply(TermsAggregationBuilder builder, String field) { - return builder.script(new org.elasticsearch.script.Script("doc['" + field + "'].values", ScriptService.ScriptType.INLINE, + return builder.script(new org.elasticsearch.script.Script("doc['" + field + "'].values", ScriptType.INLINE, CustomScriptPlugin.NAME, null)); } }; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/RangeIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/RangeIT.java index c64fc213096..eb2a668bcbd 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/RangeIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/RangeIT.java @@ -24,7 +24,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.fielddata.ScriptDocValues; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService.ScriptType; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.aggregations.AggregationTestScriptsPlugin; import org.elasticsearch.search.aggregations.Aggregator.SubAggCollectionMode; import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; @@ -34,8 +34,6 @@ import org.elasticsearch.search.aggregations.bucket.terms.Terms; import org.elasticsearch.search.aggregations.metrics.sum.Sum; import org.elasticsearch.test.ESIntegTestCase; import org.hamcrest.Matchers; -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; import java.util.ArrayList; import java.util.Collection; @@ -47,7 +45,6 @@ import java.util.function.Function; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; -import static org.elasticsearch.search.aggregations.AggregationBuilders.dateRange; import static org.elasticsearch.search.aggregations.AggregationBuilders.histogram; import static org.elasticsearch.search.aggregations.AggregationBuilders.range; import static org.elasticsearch.search.aggregations.AggregationBuilders.sum; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/SignificantTermsSignificanceScoreIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/SignificantTermsSignificanceScoreIT.java index aa5cc79ab5e..d9bf07d4d3a 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/SignificantTermsSignificanceScoreIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/SignificantTermsSignificanceScoreIT.java @@ -32,7 +32,7 @@ import org.elasticsearch.plugins.ScriptPlugin; import org.elasticsearch.plugins.SearchPlugin; import org.elasticsearch.script.NativeScriptFactory; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService.ScriptType; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.aggregations.Aggregation; import org.elasticsearch.search.aggregations.Aggregations; import org.elasticsearch.search.aggregations.bucket.filter.InternalFilter; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/StringTermsIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/StringTermsIT.java index df1741dc8b0..30f9e3c97aa 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/StringTermsIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/StringTermsIT.java @@ -30,7 +30,7 @@ import org.elasticsearch.index.mapper.IndexFieldMapper; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService.ScriptType; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.aggregations.AggregationExecutionException; import org.elasticsearch.search.aggregations.AggregationTestScriptsPlugin; import org.elasticsearch.search.aggregations.Aggregator.SubAggCollectionMode; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/AvgIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/AvgIT.java index 1d9f5484877..a1ca5411292 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/AvgIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/AvgIT.java @@ -29,7 +29,7 @@ import org.elasticsearch.script.ExecutableScript; import org.elasticsearch.script.LeafSearchScript; import org.elasticsearch.script.Script; import org.elasticsearch.script.ScriptEngineService; -import org.elasticsearch.script.ScriptService.ScriptType; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.script.SearchScript; import org.elasticsearch.search.aggregations.bucket.filter.Filter; import org.elasticsearch.search.aggregations.bucket.global.Global; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/CardinalityIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/CardinalityIT.java index 35e46b50785..4c22a38f6f6 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/CardinalityIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/CardinalityIT.java @@ -26,7 +26,7 @@ import org.elasticsearch.index.fielddata.ScriptDocValues; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.MockScriptPlugin; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService.ScriptType; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.aggregations.Aggregator.SubAggCollectionMode; import org.elasticsearch.search.aggregations.bucket.global.Global; import org.elasticsearch.search.aggregations.bucket.terms.Terms; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ExtendedStatsIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ExtendedStatsIT.java index 319a7d64230..ce700d22da0 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ExtendedStatsIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ExtendedStatsIT.java @@ -22,7 +22,7 @@ import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService.ScriptType; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.aggregations.AggregationTestScriptsPlugin; import org.elasticsearch.search.aggregations.bucket.filter.Filter; import org.elasticsearch.search.aggregations.bucket.global.Global; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/HDRPercentileRanksIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/HDRPercentileRanksIT.java index 46130fca21f..a77388fc03a 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/HDRPercentileRanksIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/HDRPercentileRanksIT.java @@ -23,7 +23,7 @@ import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService.ScriptType; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.aggregations.AggregationTestScriptsPlugin; import org.elasticsearch.search.aggregations.bucket.filter.Filter; import org.elasticsearch.search.aggregations.bucket.global.Global; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/HDRPercentilesIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/HDRPercentilesIT.java index 784b4816393..6e27e5b5042 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/HDRPercentilesIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/HDRPercentilesIT.java @@ -24,7 +24,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.CollectionUtils; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService.ScriptType; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.aggregations.AggregationTestScriptsPlugin; import org.elasticsearch.search.aggregations.bucket.filter.Filter; import org.elasticsearch.search.aggregations.bucket.global.Global; @@ -565,4 +565,4 @@ public class HDRPercentilesIT extends AbstractNumericTestCase { .getMissCount(), equalTo(1L)); } -} \ No newline at end of file +} diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/MaxIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/MaxIT.java index df65deb3696..c692082aaaa 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/MaxIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/MaxIT.java @@ -22,7 +22,7 @@ import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService.ScriptType; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.aggregations.AggregationTestScriptsPlugin; import org.elasticsearch.search.aggregations.bucket.filter.Filter; import org.elasticsearch.search.aggregations.bucket.global.Global; @@ -391,4 +391,4 @@ public class MaxIT extends AbstractNumericTestCase { assertThat(client().admin().indices().prepareStats("cache_test_idx").setRequestCache(true).get().getTotal().getRequestCache() .getMissCount(), equalTo(1L)); } -} \ No newline at end of file +} diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/MinIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/MinIT.java index 7eddcd7b53a..dc6c7d0853d 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/MinIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/MinIT.java @@ -22,7 +22,7 @@ import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService.ScriptType; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.aggregations.AggregationTestScriptsPlugin; import org.elasticsearch.search.aggregations.bucket.filter.Filter; import org.elasticsearch.search.aggregations.bucket.global.Global; @@ -404,4 +404,4 @@ public class MinIT extends AbstractNumericTestCase { assertThat(client().admin().indices().prepareStats("cache_test_idx").setRequestCache(true).get().getTotal().getRequestCache() .getMissCount(), equalTo(1L)); } -} \ No newline at end of file +} diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ScriptedMetricIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ScriptedMetricIT.java index c1a5aad556f..12f512efaaf 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ScriptedMetricIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ScriptedMetricIT.java @@ -28,7 +28,7 @@ import org.elasticsearch.env.Environment; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.MockScriptPlugin; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService.ScriptType; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.aggregations.Aggregation; import org.elasticsearch.search.aggregations.Aggregations; import org.elasticsearch.search.aggregations.bucket.global.Global; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ScriptedMetricTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ScriptedMetricTests.java index e4f96fae762..e75d14bc87a 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ScriptedMetricTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ScriptedMetricTests.java @@ -20,7 +20,7 @@ package org.elasticsearch.search.aggregations.metrics; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService.ScriptType; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.aggregations.BaseAggregationTestCase; import org.elasticsearch.search.aggregations.metrics.scripted.ScriptedMetricAggregationBuilder; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/StatsIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/StatsIT.java index 7ab44c49447..dddf74446d9 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/StatsIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/StatsIT.java @@ -25,7 +25,7 @@ import org.elasticsearch.action.search.ShardSearchFailure; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService.ScriptType; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.aggregations.AggregationTestScriptsPlugin; import org.elasticsearch.search.aggregations.bucket.filter.Filter; import org.elasticsearch.search.aggregations.bucket.global.Global; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/SumIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/SumIT.java index f4cad82b16f..b2609c76543 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/SumIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/SumIT.java @@ -29,7 +29,7 @@ import org.elasticsearch.script.ExecutableScript; import org.elasticsearch.script.LeafSearchScript; import org.elasticsearch.script.Script; import org.elasticsearch.script.ScriptEngineService; -import org.elasticsearch.script.ScriptService.ScriptType; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.script.SearchScript; import org.elasticsearch.search.aggregations.bucket.filter.Filter; import org.elasticsearch.search.aggregations.bucket.global.Global; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/TDigestPercentileRanksIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/TDigestPercentileRanksIT.java index 3a9ab247f5a..3e482229503 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/TDigestPercentileRanksIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/TDigestPercentileRanksIT.java @@ -24,7 +24,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.CollectionUtils; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService.ScriptType; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.aggregations.AggregationTestScriptsPlugin; import org.elasticsearch.search.aggregations.bucket.filter.Filter; import org.elasticsearch.search.aggregations.bucket.global.Global; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/TDigestPercentilesIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/TDigestPercentilesIT.java index 5f3fbb7e869..71f3692a25b 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/TDigestPercentilesIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/TDigestPercentilesIT.java @@ -24,7 +24,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.CollectionUtils; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService.ScriptType; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.aggregations.AggregationTestScriptsPlugin; import org.elasticsearch.search.aggregations.bucket.filter.Filter; import org.elasticsearch.search.aggregations.bucket.global.Global; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/TopHitsIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/TopHitsIT.java index 7c36fd43ea1..3cdcbf3c1c1 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/TopHitsIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/TopHitsIT.java @@ -34,8 +34,7 @@ import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.MockScriptEngine; import org.elasticsearch.script.MockScriptPlugin; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService; -import org.elasticsearch.script.ScriptService.ScriptType; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchHitField; import org.elasticsearch.search.SearchHits; @@ -584,7 +583,7 @@ public class TopHitsIT extends ESIntegTestCase { .explain(true) .storedField("text") .fieldDataField("field1") - .scriptField("script", new Script("5", ScriptService.ScriptType.INLINE, MockScriptEngine.NAME, Collections.emptyMap())) + .scriptField("script", new Script("5", ScriptType.INLINE, MockScriptEngine.NAME, Collections.emptyMap())) .fetchSource("text", null) .version(true) ) @@ -866,7 +865,7 @@ public class TopHitsIT extends ESIntegTestCase { nested("to-comments", "comments").subAggregation( topHits("top-comments").size(1).highlighter(new HighlightBuilder().field(hlField)).explain(true) .fieldDataField("comments.user") - .scriptField("script", new Script("5", ScriptService.ScriptType.INLINE, MockScriptEngine.NAME, Collections.emptyMap())).fetchSource("comments.message", null) + .scriptField("script", new Script("5", ScriptType.INLINE, MockScriptEngine.NAME, Collections.emptyMap())).fetchSource("comments.message", null) .version(true).sort("comments.date", SortOrder.ASC))).get(); assertHitCount(searchResponse, 2); Nested nested = searchResponse.getAggregations().get("to-comments"); diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ValueCountIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ValueCountIT.java index 33ec5019805..4d421892b6b 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ValueCountIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/ValueCountIT.java @@ -29,7 +29,7 @@ import org.elasticsearch.script.ExecutableScript; import org.elasticsearch.script.LeafSearchScript; import org.elasticsearch.script.Script; import org.elasticsearch.script.ScriptEngineService; -import org.elasticsearch.script.ScriptService.ScriptType; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.script.SearchScript; import org.elasticsearch.search.aggregations.bucket.global.Global; import org.elasticsearch.search.aggregations.metrics.valuecount.ValueCount; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/BucketScriptIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/BucketScriptIT.java index 101e52fcadb..47846eaabae 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/BucketScriptIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/BucketScriptIT.java @@ -26,13 +26,12 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.MockScriptPlugin; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService.ScriptType; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; import org.elasticsearch.search.aggregations.bucket.range.Range; import org.elasticsearch.search.aggregations.metrics.sum.Sum; import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy; import org.elasticsearch.test.ESIntegTestCase; -import org.joda.time.DateTime; import java.io.IOException; import java.util.ArrayList; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/BucketScriptTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/BucketScriptTests.java index 252c1247a49..4b79977cf54 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/BucketScriptTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/BucketScriptTests.java @@ -20,7 +20,7 @@ package org.elasticsearch.search.aggregations.pipeline; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService.ScriptType; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.aggregations.BasePipelineAggregationTestCase; import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy; import org.elasticsearch.search.aggregations.pipeline.bucketscript.BucketScriptPipelineAggregationBuilder; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/BucketSelectorIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/BucketSelectorIT.java index 26c0d3a4bbe..e300a72bc37 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/BucketSelectorIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/BucketSelectorIT.java @@ -26,8 +26,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.MockScriptPlugin; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService.ScriptType; -import org.elasticsearch.search.aggregations.bucket.histogram.ExtendedBounds; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; import org.elasticsearch.search.aggregations.bucket.histogram.Histogram.Bucket; import org.elasticsearch.search.aggregations.metrics.sum.Sum; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/BucketSelectorTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/BucketSelectorTests.java index 5ffbda13f9c..8cedbab8e83 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/BucketSelectorTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/BucketSelectorTests.java @@ -20,7 +20,7 @@ package org.elasticsearch.search.aggregations.pipeline; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService.ScriptType; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.aggregations.BasePipelineAggregationTestCase; import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy; import org.elasticsearch.search.aggregations.pipeline.bucketselector.BucketSelectorPipelineAggregationBuilder; diff --git a/core/src/test/java/org/elasticsearch/search/basic/TransportTwoNodesSearchIT.java b/core/src/test/java/org/elasticsearch/search/basic/TransportTwoNodesSearchIT.java index 49c24ba9952..696af4f94eb 100644 --- a/core/src/test/java/org/elasticsearch/search/basic/TransportTwoNodesSearchIT.java +++ b/core/src/test/java/org/elasticsearch/search/basic/TransportTwoNodesSearchIT.java @@ -32,7 +32,7 @@ import org.elasticsearch.index.query.GeohashCellQuery; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.query.functionscore.ScriptScoreFunctionBuilder; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.Scroll; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.aggregations.AggregationBuilders; @@ -450,7 +450,7 @@ public class TransportTwoNodesSearchIT extends ESIntegTestCase { MultiSearchResponse response = client().prepareMultiSearch() // Add custom score query with bogus script - .add(client().prepareSearch("test").setQuery(QueryBuilders.functionScoreQuery(QueryBuilders.termQuery("nid", 1), new ScriptScoreFunctionBuilder(new Script("foo", ScriptService.ScriptType.INLINE, "bar", null))))) + .add(client().prepareSearch("test").setQuery(QueryBuilders.functionScoreQuery(QueryBuilders.termQuery("nid", 1), new ScriptScoreFunctionBuilder(new Script("foo", ScriptType.INLINE, "bar", null))))) .add(client().prepareSearch("test").setQuery(QueryBuilders.termQuery("nid", 2))) .add(client().prepareSearch("test").setQuery(QueryBuilders.matchAllQuery())) .execute().actionGet(); diff --git a/core/src/test/java/org/elasticsearch/search/fetch/subphase/InnerHitsIT.java b/core/src/test/java/org/elasticsearch/search/fetch/subphase/InnerHitsIT.java index 1c9a915b2ad..519ea77f128 100644 --- a/core/src/test/java/org/elasticsearch/search/fetch/subphase/InnerHitsIT.java +++ b/core/src/test/java/org/elasticsearch/search/fetch/subphase/InnerHitsIT.java @@ -32,7 +32,7 @@ import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.MockScriptEngine; import org.elasticsearch.script.MockScriptPlugin; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchHits; import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder; @@ -167,7 +167,7 @@ public class InnerHitsIT extends ESIntegTestCase { .setExplain(true) .addDocValueField("comments.message") .addScriptField("script", - new Script("5", ScriptService.ScriptType.INLINE, MockScriptEngine.NAME, Collections.emptyMap())) + new Script("5", ScriptType.INLINE, MockScriptEngine.NAME, Collections.emptyMap())) .setSize(1) )).get(); assertNoFailures(response); @@ -301,7 +301,7 @@ public class InnerHitsIT extends ESIntegTestCase { .addDocValueField("message") .setHighlightBuilder(new HighlightBuilder().field("message")) .setExplain(true).setSize(1) - .addScriptField("script", new Script("5", ScriptService.ScriptType.INLINE, + .addScriptField("script", new Script("5", ScriptType.INLINE, MockScriptEngine.NAME, Collections.emptyMap())) ) ).get(); diff --git a/core/src/test/java/org/elasticsearch/search/fields/SearchFieldsIT.java b/core/src/test/java/org/elasticsearch/search/fields/SearchFieldsIT.java index 4e43537099b..9e3cc14eed0 100644 --- a/core/src/test/java/org/elasticsearch/search/fields/SearchFieldsIT.java +++ b/core/src/test/java/org/elasticsearch/search/fields/SearchFieldsIT.java @@ -36,7 +36,7 @@ import org.elasticsearch.plugins.Plugin; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.script.MockScriptPlugin; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService.ScriptType; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchHitField; import org.elasticsearch.search.builder.SearchSourceBuilder; diff --git a/core/src/test/java/org/elasticsearch/search/functionscore/ExplainableScriptIT.java b/core/src/test/java/org/elasticsearch/search/functionscore/ExplainableScriptIT.java index 1c87ccfe4cb..dacd11c843f 100644 --- a/core/src/test/java/org/elasticsearch/search/functionscore/ExplainableScriptIT.java +++ b/core/src/test/java/org/elasticsearch/search/functionscore/ExplainableScriptIT.java @@ -32,7 +32,7 @@ import org.elasticsearch.script.ExecutableScript; import org.elasticsearch.script.ExplainableSearchScript; import org.elasticsearch.script.NativeScriptFactory; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService.ScriptType; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchHits; import org.elasticsearch.test.ESIntegTestCase; diff --git a/core/src/test/java/org/elasticsearch/search/functionscore/FunctionScoreIT.java b/core/src/test/java/org/elasticsearch/search/functionscore/FunctionScoreIT.java index 3854d200116..2bd6de9e647 100644 --- a/core/src/test/java/org/elasticsearch/search/functionscore/FunctionScoreIT.java +++ b/core/src/test/java/org/elasticsearch/search/functionscore/FunctionScoreIT.java @@ -48,7 +48,8 @@ import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.index.query.QueryBuilders.functionScoreQuery; import static org.elasticsearch.index.query.QueryBuilders.termQuery; import static org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders.scriptFunction; -import static org.elasticsearch.script.ScriptService.ScriptType; + +import org.elasticsearch.script.ScriptType; import static org.elasticsearch.search.aggregations.AggregationBuilders.terms; import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; diff --git a/core/src/test/java/org/elasticsearch/search/functionscore/RandomScoreFunctionIT.java b/core/src/test/java/org/elasticsearch/search/functionscore/RandomScoreFunctionIT.java index 9c2b41eabe6..cd283605503 100644 --- a/core/src/test/java/org/elasticsearch/search/functionscore/RandomScoreFunctionIT.java +++ b/core/src/test/java/org/elasticsearch/search/functionscore/RandomScoreFunctionIT.java @@ -27,7 +27,7 @@ import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.MockScriptPlugin; import org.elasticsearch.script.ScoreAccessor; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService.ScriptType; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.SearchHit; import org.elasticsearch.test.ESIntegTestCase; import org.hamcrest.CoreMatchers; diff --git a/core/src/test/java/org/elasticsearch/search/geo/GeoDistanceIT.java b/core/src/test/java/org/elasticsearch/search/geo/GeoDistanceIT.java index 8297b5e0187..841b6bcd987 100644 --- a/core/src/test/java/org/elasticsearch/search/geo/GeoDistanceIT.java +++ b/core/src/test/java/org/elasticsearch/search/geo/GeoDistanceIT.java @@ -35,7 +35,7 @@ import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.MockScriptPlugin; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService.ScriptType; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.aggregations.AggregationBuilders; import org.elasticsearch.search.aggregations.Aggregations; import org.elasticsearch.search.aggregations.bucket.range.Range; diff --git a/core/src/test/java/org/elasticsearch/search/scriptfilter/ScriptQuerySearchIT.java b/core/src/test/java/org/elasticsearch/search/scriptfilter/ScriptQuerySearchIT.java index 6422bf7a134..f01f6d5d0e1 100644 --- a/core/src/test/java/org/elasticsearch/search/scriptfilter/ScriptQuerySearchIT.java +++ b/core/src/test/java/org/elasticsearch/search/scriptfilter/ScriptQuerySearchIT.java @@ -26,7 +26,7 @@ import org.elasticsearch.index.fielddata.ScriptDocValues; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.MockScriptPlugin; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService.ScriptType; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.sort.SortOrder; import org.elasticsearch.test.ESIntegTestCase; diff --git a/core/src/test/java/org/elasticsearch/search/sort/AbstractSortTestCase.java b/core/src/test/java/org/elasticsearch/search/sort/AbstractSortTestCase.java index c12027ea6f5..006f69e4774 100644 --- a/core/src/test/java/org/elasticsearch/search/sort/AbstractSortTestCase.java +++ b/core/src/test/java/org/elasticsearch/search/sort/AbstractSortTestCase.java @@ -61,6 +61,7 @@ import org.elasticsearch.script.ScriptEngineRegistry; import org.elasticsearch.script.ScriptService; import org.elasticsearch.script.ScriptServiceTests.TestEngineService; import org.elasticsearch.script.ScriptSettings; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.SearchModule; import org.elasticsearch.test.ESTestCase; diff --git a/core/src/test/java/org/elasticsearch/search/sort/ScriptSortBuilderTests.java b/core/src/test/java/org/elasticsearch/search/sort/ScriptSortBuilderTests.java index 82d0de87801..5146660aa09 100644 --- a/core/src/test/java/org/elasticsearch/search/sort/ScriptSortBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/search/sort/ScriptSortBuilderTests.java @@ -26,7 +26,7 @@ import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService.ScriptType; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.sort.ScriptSortBuilder.ScriptSortType; diff --git a/core/src/test/java/org/elasticsearch/search/sort/SimpleSortIT.java b/core/src/test/java/org/elasticsearch/search/sort/SimpleSortIT.java index 24a82526eda..92dd133b24d 100644 --- a/core/src/test/java/org/elasticsearch/search/sort/SimpleSortIT.java +++ b/core/src/test/java/org/elasticsearch/search/sort/SimpleSortIT.java @@ -48,7 +48,8 @@ import java.util.function.Function; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; import static org.elasticsearch.index.query.QueryBuilders.termQuery; -import static org.elasticsearch.script.ScriptService.ScriptType; + +import org.elasticsearch.script.ScriptType; import static org.elasticsearch.search.sort.SortBuilders.scriptSort; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount; diff --git a/core/src/test/java/org/elasticsearch/search/stats/SearchStatsIT.java b/core/src/test/java/org/elasticsearch/search/stats/SearchStatsIT.java index 1c296a3724a..9cc9811358f 100644 --- a/core/src/test/java/org/elasticsearch/search/stats/SearchStatsIT.java +++ b/core/src/test/java/org/elasticsearch/search/stats/SearchStatsIT.java @@ -34,7 +34,7 @@ import org.elasticsearch.index.search.stats.SearchStats.Stats; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.MockScriptPlugin; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService.ScriptType; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder; import org.elasticsearch.test.ESIntegTestCase; diff --git a/core/src/test/java/org/elasticsearch/update/TimestampTTLBWIT.java b/core/src/test/java/org/elasticsearch/update/TimestampTTLBWIT.java index ac142fa461d..cdeec658447 100644 --- a/core/src/test/java/org/elasticsearch/update/TimestampTTLBWIT.java +++ b/core/src/test/java/org/elasticsearch/update/TimestampTTLBWIT.java @@ -31,7 +31,7 @@ import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.index.engine.DocumentMissingException; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchHitField; import org.elasticsearch.search.sort.SortOrder; @@ -115,7 +115,7 @@ public class TimestampTTLBWIT extends ESIntegTestCase { try { client().prepareUpdate(indexOrAlias(), "type1", "1") - .setScript(new Script("field", ScriptService.ScriptType.INLINE, "field_inc", null)).execute().actionGet(); + .setScript(new Script("field", ScriptType.INLINE, "field_inc", null)).execute().actionGet(); fail(); } catch (DocumentMissingException e) { // all is well @@ -127,14 +127,14 @@ public class TimestampTTLBWIT extends ESIntegTestCase { long ttl = ((Number) getResponse.getField("_ttl").getValue()).longValue(); assertThat(ttl, greaterThan(0L)); client().prepareUpdate(indexOrAlias(), "type1", "2") - .setScript(new Script("field", ScriptService.ScriptType.INLINE, "field_inc", null)).execute().actionGet(); + .setScript(new Script("field", ScriptType.INLINE, "field_inc", null)).execute().actionGet(); getResponse = client().prepareGet("test", "type1", "2").setStoredFields("_ttl").execute().actionGet(); ttl = ((Number) getResponse.getField("_ttl").getValue()).longValue(); assertThat(ttl, greaterThan(0L)); // check TTL update client().prepareUpdate(indexOrAlias(), "type1", "2") - .setScript(new Script("", ScriptService.ScriptType.INLINE, "put_values", + .setScript(new Script("", ScriptType.INLINE, "put_values", Collections.singletonMap("_ctx", Collections.singletonMap("_ttl", 3600000)))).execute().actionGet(); getResponse = client().prepareGet("test", "type1", "2").setStoredFields("_ttl").execute().actionGet(); ttl = ((Number) getResponse.getField("_ttl").getValue()).longValue(); @@ -144,7 +144,7 @@ public class TimestampTTLBWIT extends ESIntegTestCase { // check timestamp update client().prepareIndex("test", "type1", "3").setSource("field", 1).setRefreshPolicy(IMMEDIATE).get(); client().prepareUpdate(indexOrAlias(), "type1", "3") - .setScript(new Script("", ScriptService.ScriptType.INLINE, "put_values", + .setScript(new Script("", ScriptType.INLINE, "put_values", Collections.singletonMap("_ctx", Collections.singletonMap("_timestamp", "2009-11-15T14:12:12")))).execute() .actionGet(); getResponse = client().prepareGet("test", "type1", "3").setStoredFields("_timestamp").execute().actionGet(); @@ -198,7 +198,7 @@ public class TimestampTTLBWIT extends ESIntegTestCase { // Update the first object and note context variables values UpdateResponse updateResponse = client().prepareUpdate("test", "subtype1", "id1") .setRouting("routing1") - .setScript(new Script("", ScriptService.ScriptType.INLINE, "extract_ctx", null)) + .setScript(new Script("", ScriptType.INLINE, "extract_ctx", null)) .execute().actionGet(); assertEquals(2, updateResponse.getVersion()); @@ -215,7 +215,7 @@ public class TimestampTTLBWIT extends ESIntegTestCase { // Idem with the second object updateResponse = client().prepareUpdate("test", "type1", "parentId1") - .setScript(new Script("", ScriptService.ScriptType.INLINE, "extract_ctx", null)) + .setScript(new Script("", ScriptType.INLINE, "extract_ctx", null)) .execute().actionGet(); assertEquals(2, updateResponse.getVersion()); diff --git a/core/src/test/java/org/elasticsearch/update/UpdateByNativeScriptIT.java b/core/src/test/java/org/elasticsearch/update/UpdateByNativeScriptIT.java index b8c78f5e311..bad89b7ab62 100644 --- a/core/src/test/java/org/elasticsearch/update/UpdateByNativeScriptIT.java +++ b/core/src/test/java/org/elasticsearch/update/UpdateByNativeScriptIT.java @@ -26,8 +26,7 @@ import org.elasticsearch.script.ExecutableScript; import org.elasticsearch.script.NativeScriptEngineService; import org.elasticsearch.script.NativeScriptFactory; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptModule; -import org.elasticsearch.script.ScriptService; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.elasticsearch.test.ESIntegTestCase.Scope; @@ -58,7 +57,7 @@ public class UpdateByNativeScriptIT extends ESIntegTestCase { Map params = new HashMap<>(); params.put("foo", "SETVALUE"); client().prepareUpdate("test", "type", "1") - .setScript(new Script("custom", ScriptService.ScriptType.INLINE, NativeScriptEngineService.NAME, params)).get(); + .setScript(new Script("custom", ScriptType.INLINE, NativeScriptEngineService.NAME, params)).get(); Map data = client().prepareGet("test", "type", "1").get().getSource(); assertThat(data, hasKey("foo")); diff --git a/core/src/test/java/org/elasticsearch/update/UpdateIT.java b/core/src/test/java/org/elasticsearch/update/UpdateIT.java index fc360effb03..b662f7034c5 100644 --- a/core/src/test/java/org/elasticsearch/update/UpdateIT.java +++ b/core/src/test/java/org/elasticsearch/update/UpdateIT.java @@ -44,7 +44,7 @@ import org.elasticsearch.script.CompiledScript; import org.elasticsearch.script.ExecutableScript; import org.elasticsearch.script.Script; import org.elasticsearch.script.ScriptEngineService; -import org.elasticsearch.script.ScriptService; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.script.SearchScript; import org.elasticsearch.search.lookup.SearchLookup; import org.elasticsearch.test.ESIntegTestCase; @@ -369,7 +369,7 @@ public class UpdateIT extends ESIntegTestCase { UpdateResponse updateResponse = client().prepareUpdate(indexOrAlias(), "type1", "1") .setUpsert(XContentFactory.jsonBuilder().startObject().field("field", 1).endObject()) - .setScript(new Script("field", ScriptService.ScriptType.INLINE, "field_inc", null)) + .setScript(new Script("field", ScriptType.INLINE, "field_inc", null)) .execute().actionGet(); assertEquals(DocWriteResponse.Result.CREATED, updateResponse.getResult()); assertThat(updateResponse.getIndex(), equalTo("test")); @@ -381,7 +381,7 @@ public class UpdateIT extends ESIntegTestCase { updateResponse = client().prepareUpdate(indexOrAlias(), "type1", "1") .setUpsert(XContentFactory.jsonBuilder().startObject().field("field", 1).endObject()) - .setScript(new Script("field", ScriptService.ScriptType.INLINE, "field_inc", null)) + .setScript(new Script("field", ScriptType.INLINE, "field_inc", null)) .execute().actionGet(); assertEquals(DocWriteResponse.Result.UPDATED, updateResponse.getResult()); assertThat(updateResponse.getIndex(), equalTo("test")); @@ -410,7 +410,7 @@ public class UpdateIT extends ESIntegTestCase { UpdateResponse updateResponse = client().prepareUpdate(indexOrAlias(), "type1", "1") .setUpsert(XContentFactory.jsonBuilder().startObject().field("balance", openingBalance).endObject()) .setScriptedUpsert(true) - .setScript(new Script("", ScriptService.ScriptType.INLINE, "scripted_upsert", params)) + .setScript(new Script("", ScriptType.INLINE, "scripted_upsert", params)) .execute().actionGet(); assertEquals(DocWriteResponse.Result.CREATED, updateResponse.getResult()); assertThat(updateResponse.getIndex(), equalTo("test")); @@ -424,7 +424,7 @@ public class UpdateIT extends ESIntegTestCase { updateResponse = client().prepareUpdate(indexOrAlias(), "type1", "1") .setUpsert(XContentFactory.jsonBuilder().startObject().field("balance", openingBalance).endObject()) .setScriptedUpsert(true) - .setScript(new Script("", ScriptService.ScriptType.INLINE, "scripted_upsert", params)) + .setScript(new Script("", ScriptType.INLINE, "scripted_upsert", params)) .execute().actionGet(); assertEquals(DocWriteResponse.Result.UPDATED, updateResponse.getResult()); assertThat(updateResponse.getIndex(), equalTo("test")); @@ -468,7 +468,7 @@ public class UpdateIT extends ESIntegTestCase { UpdateResponse updateResponse = client().prepareUpdate(indexOrAlias(), "type1", "1") .setUpsert(XContentFactory.jsonBuilder().startObject().field("bar", "baz").endObject()) - .setScript(new Script("", ScriptService.ScriptType.INLINE, "put_values", Collections.singletonMap("extra", "foo"))) + .setScript(new Script("", ScriptType.INLINE, "put_values", Collections.singletonMap("extra", "foo"))) .setFetchSource(true) .execute().actionGet(); @@ -480,7 +480,7 @@ public class UpdateIT extends ESIntegTestCase { updateResponse = client().prepareUpdate(indexOrAlias(), "type1", "1") .setUpsert(XContentFactory.jsonBuilder().startObject().field("bar", "baz").endObject()) - .setScript(new Script("", ScriptService.ScriptType.INLINE, "put_values", Collections.singletonMap("extra", "foo"))) + .setScript(new Script("", ScriptType.INLINE, "put_values", Collections.singletonMap("extra", "foo"))) .setFields("_source") .execute().actionGet(); @@ -498,24 +498,24 @@ public class UpdateIT extends ESIntegTestCase { index("test", "type", "1", "text", "value"); // version is now 1 assertThrows(client().prepareUpdate(indexOrAlias(), "type", "1") - .setScript(new Script("", ScriptService.ScriptType.INLINE, "put_values", Collections.singletonMap("text", "v2"))).setVersion(2) + .setScript(new Script("", ScriptType.INLINE, "put_values", Collections.singletonMap("text", "v2"))).setVersion(2) .execute(), VersionConflictEngineException.class); client().prepareUpdate(indexOrAlias(), "type", "1") - .setScript(new Script("", ScriptService.ScriptType.INLINE, "put_values", Collections.singletonMap("text", "v2"))).setVersion(1).get(); + .setScript(new Script("", ScriptType.INLINE, "put_values", Collections.singletonMap("text", "v2"))).setVersion(1).get(); assertThat(client().prepareGet("test", "type", "1").get().getVersion(), equalTo(2L)); // and again with a higher version.. client().prepareUpdate(indexOrAlias(), "type", "1") - .setScript(new Script("", ScriptService.ScriptType.INLINE, "put_values", Collections.singletonMap("text", "v3"))).setVersion(2).get(); + .setScript(new Script("", ScriptType.INLINE, "put_values", Collections.singletonMap("text", "v3"))).setVersion(2).get(); assertThat(client().prepareGet("test", "type", "1").get().getVersion(), equalTo(3L)); // after delete client().prepareDelete("test", "type", "1").get(); assertThrows(client().prepareUpdate("test", "type", "1") - .setScript(new Script("", ScriptService.ScriptType.INLINE, "put_values", Collections.singletonMap("text", "v2"))).setVersion(3) + .setScript(new Script("", ScriptType.INLINE, "put_values", Collections.singletonMap("text", "v2"))).setVersion(3) .execute(), DocumentMissingException.class); @@ -523,7 +523,7 @@ public class UpdateIT extends ESIntegTestCase { client().prepareIndex("test", "type", "2").setSource("text", "value").setVersion(10).setVersionType(VersionType.EXTERNAL).get(); assertThrows(client().prepareUpdate(indexOrAlias(), "type", "2") - .setScript(new Script("", ScriptService.ScriptType.INLINE, "put_values", Collections.singletonMap("text", "v2"))).setVersion(2) + .setScript(new Script("", ScriptType.INLINE, "put_values", Collections.singletonMap("text", "v2"))).setVersion(2) .setVersionType(VersionType.EXTERNAL).execute(), ActionRequestValidationException.class); @@ -535,7 +535,7 @@ public class UpdateIT extends ESIntegTestCase { // With internal versions, tt means "if object is there with version X, update it or explode. If it is not there, index. client().prepareUpdate(indexOrAlias(), "type", "3") - .setScript(new Script("", ScriptService.ScriptType.INLINE, "put_values", Collections.singletonMap("text", "v2"))) + .setScript(new Script("", ScriptType.INLINE, "put_values", Collections.singletonMap("text", "v2"))) .setVersion(10).setUpsert("{ \"text\": \"v0\" }").get(); get = get("test", "type", "3"); assertThat(get.getVersion(), equalTo(1L)); @@ -548,7 +548,7 @@ public class UpdateIT extends ESIntegTestCase { public void testIndexAutoCreation() throws Exception { UpdateResponse updateResponse = client().prepareUpdate("test", "type1", "1") .setUpsert(XContentFactory.jsonBuilder().startObject().field("bar", "baz").endObject()) - .setScript(new Script("", ScriptService.ScriptType.INLINE, "put_values", Collections.singletonMap("extra", "foo"))) + .setScript(new Script("", ScriptType.INLINE, "put_values", Collections.singletonMap("extra", "foo"))) .setFetchSource(true) .execute().actionGet(); @@ -565,7 +565,7 @@ public class UpdateIT extends ESIntegTestCase { try { client().prepareUpdate(indexOrAlias(), "type1", "1") - .setScript(new Script("field", ScriptService.ScriptType.INLINE, "field_inc", null)).execute().actionGet(); + .setScript(new Script("field", ScriptType.INLINE, "field_inc", null)).execute().actionGet(); fail(); } catch (DocumentMissingException e) { // all is well @@ -574,7 +574,7 @@ public class UpdateIT extends ESIntegTestCase { client().prepareIndex("test", "type1", "1").setSource("field", 1).execute().actionGet(); UpdateResponse updateResponse = client().prepareUpdate(indexOrAlias(), "type1", "1") - .setScript(new Script("field", ScriptService.ScriptType.INLINE, "field_inc", null)).execute().actionGet(); + .setScript(new Script("field", ScriptType.INLINE, "field_inc", null)).execute().actionGet(); assertThat(updateResponse.getVersion(), equalTo(2L)); assertEquals(DocWriteResponse.Result.UPDATED, updateResponse.getResult()); assertThat(updateResponse.getIndex(), equalTo("test")); @@ -587,7 +587,7 @@ public class UpdateIT extends ESIntegTestCase { Map params = new HashMap<>(); params.put("inc", 3); updateResponse = client().prepareUpdate(indexOrAlias(), "type1", "1") - .setScript(new Script("field", ScriptService.ScriptType.INLINE, "field_inc", params)).execute().actionGet(); + .setScript(new Script("field", ScriptType.INLINE, "field_inc", params)).execute().actionGet(); assertThat(updateResponse.getVersion(), equalTo(3L)); assertEquals(DocWriteResponse.Result.UPDATED, updateResponse.getResult()); assertThat(updateResponse.getIndex(), equalTo("test")); @@ -599,7 +599,7 @@ public class UpdateIT extends ESIntegTestCase { // check noop updateResponse = client().prepareUpdate(indexOrAlias(), "type1", "1") - .setScript(new Script("", ScriptService.ScriptType.INLINE, "put_values", Collections.singletonMap("_ctx", Collections.singletonMap("op", "none")))).execute().actionGet(); + .setScript(new Script("", ScriptType.INLINE, "put_values", Collections.singletonMap("_ctx", Collections.singletonMap("op", "none")))).execute().actionGet(); assertThat(updateResponse.getVersion(), equalTo(3L)); assertEquals(DocWriteResponse.Result.NOOP, updateResponse.getResult()); assertThat(updateResponse.getIndex(), equalTo("test")); @@ -611,7 +611,7 @@ public class UpdateIT extends ESIntegTestCase { // check delete updateResponse = client().prepareUpdate(indexOrAlias(), "type1", "1") - .setScript(new Script("", ScriptService.ScriptType.INLINE, "put_values", Collections.singletonMap("_ctx", Collections.singletonMap("op", "delete")))).execute().actionGet(); + .setScript(new Script("", ScriptType.INLINE, "put_values", Collections.singletonMap("_ctx", Collections.singletonMap("op", "delete")))).execute().actionGet(); assertThat(updateResponse.getVersion(), equalTo(4L)); assertEquals(DocWriteResponse.Result.DELETED, updateResponse.getResult()); assertThat(updateResponse.getIndex(), equalTo("test")); @@ -624,7 +624,7 @@ public class UpdateIT extends ESIntegTestCase { // check fields parameter client().prepareIndex("test", "type1", "1").setSource("field", 1).execute().actionGet(); updateResponse = client().prepareUpdate(indexOrAlias(), "type1", "1") - .setScript(new Script("field", ScriptService.ScriptType.INLINE, "field_inc", null)) + .setScript(new Script("field", ScriptType.INLINE, "field_inc", null)) .setFields("field") .setFetchSource(true) .execute().actionGet(); @@ -637,7 +637,7 @@ public class UpdateIT extends ESIntegTestCase { // check _source parameter client().prepareIndex("test", "type1", "1").setSource("field1", 1, "field2", 2).execute().actionGet(); updateResponse = client().prepareUpdate(indexOrAlias(), "type1", "1") - .setScript(new Script("field1", ScriptService.ScriptType.INLINE, "field_inc", null)) + .setScript(new Script("field1", ScriptType.INLINE, "field_inc", null)) .setFetchSource("field1", "field2") .get(); assertThat(updateResponse.getIndex(), equalTo("test")); @@ -700,7 +700,7 @@ public class UpdateIT extends ESIntegTestCase { try { client().prepareUpdate(indexOrAlias(), "type1", "1") .setDoc(XContentFactory.jsonBuilder().startObject().field("field", 1).endObject()) - .setScript(new Script("field", ScriptService.ScriptType.INLINE, "field_inc", null)) + .setScript(new Script("field", ScriptType.INLINE, "field_inc", null)) .execute().actionGet(); fail("Should have thrown ActionRequestValidationException"); } catch (ActionRequestValidationException e) { @@ -715,7 +715,7 @@ public class UpdateIT extends ESIntegTestCase { ensureGreen(); try { client().prepareUpdate(indexOrAlias(), "type1", "1") - .setScript(new Script("field", ScriptService.ScriptType.INLINE, "field_inc", null)) + .setScript(new Script("field", ScriptType.INLINE, "field_inc", null)) .setDocAsUpsert(true) .execute().actionGet(); fail("Should have thrown ActionRequestValidationException"); @@ -767,7 +767,7 @@ public class UpdateIT extends ESIntegTestCase { // Update the first object and note context variables values UpdateResponse updateResponse = client().prepareUpdate("test", "subtype1", "id1") .setRouting("routing1") - .setScript(new Script("", ScriptService.ScriptType.INLINE, "extract_ctx", null)) + .setScript(new Script("", ScriptType.INLINE, "extract_ctx", null)) .execute().actionGet(); assertEquals(2, updateResponse.getVersion()); @@ -783,7 +783,7 @@ public class UpdateIT extends ESIntegTestCase { // Idem with the second object updateResponse = client().prepareUpdate("test", "type1", "parentId1") - .setScript(new Script("", ScriptService.ScriptType.INLINE, "extract_ctx", null)) + .setScript(new Script("", ScriptType.INLINE, "extract_ctx", null)) .execute().actionGet(); assertEquals(2, updateResponse.getVersion()); @@ -822,13 +822,13 @@ public class UpdateIT extends ESIntegTestCase { } if (useBulkApi) { UpdateRequestBuilder updateRequestBuilder = client().prepareUpdate(indexOrAlias(), "type1", Integer.toString(i)) - .setScript(new Script("field", ScriptService.ScriptType.INLINE, "field_inc", null)) + .setScript(new Script("field", ScriptType.INLINE, "field_inc", null)) .setRetryOnConflict(Integer.MAX_VALUE) .setUpsert(jsonBuilder().startObject().field("field", 1).endObject()); client().prepareBulk().add(updateRequestBuilder).execute().actionGet(); } else { client().prepareUpdate(indexOrAlias(), "type1", Integer.toString(i)) - .setScript(new Script("field", ScriptService.ScriptType.INLINE, "field_inc", null)) + .setScript(new Script("field", ScriptType.INLINE, "field_inc", null)) .setRetryOnConflict(Integer.MAX_VALUE) .setUpsert(jsonBuilder().startObject().field("field", 1).endObject()) .execute().actionGet(); @@ -948,7 +948,7 @@ public class UpdateIT extends ESIntegTestCase { updateRequestsOutstanding.acquire(); try { UpdateRequest ur = client().prepareUpdate("test", "type1", Integer.toString(j)) - .setScript(new Script("field", ScriptService.ScriptType.INLINE, "field_inc", null)) + .setScript(new Script("field", ScriptType.INLINE, "field_inc", null)) .setRetryOnConflict(retryOnConflict) .setUpsert(jsonBuilder().startObject().field("field", 1).endObject()) .request(); @@ -1048,7 +1048,7 @@ public class UpdateIT extends ESIntegTestCase { //All the previous operations should be complete or failed at this point for (int i = 0; i < numberOfIdsPerThread; ++i) { UpdateResponse ur = client().prepareUpdate("test", "type1", Integer.toString(i)) - .setScript(new Script("field", ScriptService.ScriptType.INLINE, "field_inc", null)) + .setScript(new Script("field", ScriptType.INLINE, "field_inc", null)) .setRetryOnConflict(Integer.MAX_VALUE) .setUpsert(jsonBuilder().startObject().field("field", 1).endObject()) .execute().actionGet(); diff --git a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/ScriptProcessor.java b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/ScriptProcessor.java index 7129d2e3343..160fd445e43 100644 --- a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/ScriptProcessor.java +++ b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/ScriptProcessor.java @@ -36,9 +36,9 @@ import static org.elasticsearch.ingest.ConfigurationUtils.newConfigurationExcept import static org.elasticsearch.ingest.ConfigurationUtils.readOptionalMap; import static org.elasticsearch.ingest.ConfigurationUtils.readOptionalStringProperty; import static org.elasticsearch.ingest.ConfigurationUtils.readStringProperty; -import static org.elasticsearch.script.ScriptService.ScriptType.FILE; -import static org.elasticsearch.script.ScriptService.ScriptType.INLINE; -import static org.elasticsearch.script.ScriptService.ScriptType.STORED; +import static org.elasticsearch.script.ScriptType.FILE; +import static org.elasticsearch.script.ScriptType.INLINE; +import static org.elasticsearch.script.ScriptType.STORED; /** * Processor that adds new fields with their corresponding values. If the field is already present, its value diff --git a/modules/lang-expression/src/test/java/org/elasticsearch/script/expression/ExpressionTests.java b/modules/lang-expression/src/test/java/org/elasticsearch/script/expression/ExpressionTests.java index 2b74aaa9f1e..b9c628926e3 100644 --- a/modules/lang-expression/src/test/java/org/elasticsearch/script/expression/ExpressionTests.java +++ b/modules/lang-expression/src/test/java/org/elasticsearch/script/expression/ExpressionTests.java @@ -23,7 +23,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.IndexService; import org.elasticsearch.script.CompiledScript; import org.elasticsearch.script.ScriptException; -import org.elasticsearch.script.ScriptService.ScriptType; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.script.SearchScript; import org.elasticsearch.search.lookup.SearchLookup; import org.elasticsearch.test.ESSingleNodeTestCase; @@ -34,7 +34,7 @@ import java.util.Collections; public class ExpressionTests extends ESSingleNodeTestCase { ExpressionScriptEngineService service; SearchLookup lookup; - + @Override public void setUp() throws Exception { super.setUp(); @@ -42,7 +42,7 @@ public class ExpressionTests extends ESSingleNodeTestCase { service = new ExpressionScriptEngineService(Settings.EMPTY); lookup = new SearchLookup(index.mapperService(), index.fieldData(), null); } - + private SearchScript compile(String expression) { Object compiled = service.compile(null, expression, Collections.emptyMap()); return service.search(new CompiledScript(ScriptType.INLINE, "randomName", "expression", compiled), lookup, Collections.emptyMap()); @@ -54,14 +54,14 @@ public class ExpressionTests extends ESSingleNodeTestCase { assertTrue(compile("1/_score").needsScores()); assertTrue(compile("doc['d'].value * _score").needsScores()); } - + public void testCompileError() { ScriptException e = expectThrows(ScriptException.class, () -> { compile("doc['d'].value * *@#)(@$*@#$ + 4"); }); assertTrue(e.getCause() instanceof ParseException); } - + public void testLinkError() { ScriptException e = expectThrows(ScriptException.class, () -> { compile("doc['e'].value * 5"); diff --git a/modules/lang-expression/src/test/java/org/elasticsearch/script/expression/IndexedExpressionTests.java b/modules/lang-expression/src/test/java/org/elasticsearch/script/expression/IndexedExpressionTests.java index 731e8760e80..d8eeeed8d5b 100644 --- a/modules/lang-expression/src/test/java/org/elasticsearch/script/expression/IndexedExpressionTests.java +++ b/modules/lang-expression/src/test/java/org/elasticsearch/script/expression/IndexedExpressionTests.java @@ -23,8 +23,7 @@ import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService; -import org.elasticsearch.script.ScriptService.ScriptType; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.aggregations.AggregationBuilders; import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.test.ESIntegTestCase; @@ -59,7 +58,7 @@ public class IndexedExpressionTests extends ESIntegTestCase { client().prepareIndex("test", "scriptTest", "1").setSource("{\"theField\":\"foo\"}").get(); try { client().prepareUpdate("test", "scriptTest", "1") - .setScript(new Script("script1", ScriptService.ScriptType.STORED, ExpressionScriptEngineService.NAME, null)).get(); + .setScript(new Script("script1", ScriptType.STORED, ExpressionScriptEngineService.NAME, null)).get(); fail("update script should have been rejected"); } catch(Exception e) { assertThat(e.getMessage(), containsString("failed to execute script")); diff --git a/modules/lang-expression/src/test/java/org/elasticsearch/script/expression/MoreExpressionTests.java b/modules/lang-expression/src/test/java/org/elasticsearch/script/expression/MoreExpressionTests.java index d71d09f2f37..b0c97fcb5c0 100644 --- a/modules/lang-expression/src/test/java/org/elasticsearch/script/expression/MoreExpressionTests.java +++ b/modules/lang-expression/src/test/java/org/elasticsearch/script/expression/MoreExpressionTests.java @@ -36,7 +36,7 @@ import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.CompiledScript; import org.elasticsearch.script.GeneralScriptException; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService.ScriptType; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.SearchHits; import org.elasticsearch.search.aggregations.AggregationBuilders; import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; @@ -164,7 +164,7 @@ public class MoreExpressionTests extends ESIntegTestCase { assertEquals(1985.0, hits.getAt(0).field("foo").getValue(), 0.0D); assertEquals(1983.0, hits.getAt(1).field("foo").getValue(), 0.0D); } - + public void testDateObjectMethods() throws Exception { ElasticsearchAssertions.assertAcked(prepareCreate("test").addMapping("doc", "date0", "type=date", "date1", "type=date")); ensureGreen("test"); @@ -257,7 +257,7 @@ public class MoreExpressionTests extends ESIntegTestCase { assertEquals(2.5, hits.getAt(0).field("foo").getValue(), 0.0D); assertEquals(5.0, hits.getAt(1).field("foo").getValue(), 0.0D); assertEquals(1.5, hits.getAt(2).field("foo").getValue(), 0.0D); - + // make sure count() works for missing rsp = buildRequest("doc['double2'].count()").get(); assertSearchResponse(rsp); @@ -266,7 +266,7 @@ public class MoreExpressionTests extends ESIntegTestCase { assertEquals(1.0, hits.getAt(0).field("foo").getValue(), 0.0D); assertEquals(0.0, hits.getAt(1).field("foo").getValue(), 0.0D); assertEquals(0.0, hits.getAt(2).field("foo").getValue(), 0.0D); - + // make sure .empty works in the same way rsp = buildRequest("doc['double2'].empty ? 5.0 : 2.0").get(); assertSearchResponse(rsp); @@ -616,7 +616,7 @@ public class MoreExpressionTests extends ESIntegTestCase { } } } - + public void testGeo() throws Exception { XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().startObject().startObject("type1") .startObject("properties").startObject("location").field("type", "geo_point"); @@ -649,7 +649,7 @@ public class MoreExpressionTests extends ESIntegTestCase { assertEquals(1, rsp.getHits().getTotalHits()); assertEquals(3170D, rsp.getHits().getAt(0).field("foo").getValue(), 50D); } - + public void testBoolean() throws Exception { XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().startObject().startObject("type1") .startObject("properties").startObject("vip").field("type", "boolean"); diff --git a/modules/lang-groovy/src/test/java/org/elasticsearch/script/groovy/GroovyIndexedScriptTests.java b/modules/lang-groovy/src/test/java/org/elasticsearch/script/groovy/GroovyIndexedScriptTests.java index b0d5fd3366b..e273b52dad0 100644 --- a/modules/lang-groovy/src/test/java/org/elasticsearch/script/groovy/GroovyIndexedScriptTests.java +++ b/modules/lang-groovy/src/test/java/org/elasticsearch/script/groovy/GroovyIndexedScriptTests.java @@ -28,10 +28,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService; -import org.elasticsearch.script.ScriptService.ScriptType; -import org.elasticsearch.script.groovy.GroovyPlugin; -import org.elasticsearch.script.groovy.GroovyScriptEngineService; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.aggregations.AggregationBuilders; import org.elasticsearch.search.builder.SearchSourceBuilder; @@ -138,7 +135,7 @@ public class GroovyIndexedScriptTests extends ESIntegTestCase { client().prepareIndex("test", "scriptTest", "1").setSource("{\"theField\":\"foo\"}").get(); try { client().prepareUpdate("test", "scriptTest", "1") - .setScript(new Script("script1", ScriptService.ScriptType.STORED, GroovyScriptEngineService.NAME, null)).get(); + .setScript(new Script("script1", ScriptType.STORED, GroovyScriptEngineService.NAME, null)).get(); fail("update script should have been rejected"); } catch (Exception e) { assertThat(e.getMessage(), containsString("failed to execute script")); diff --git a/modules/lang-groovy/src/test/java/org/elasticsearch/script/groovy/GroovyScriptTests.java b/modules/lang-groovy/src/test/java/org/elasticsearch/script/groovy/GroovyScriptTests.java index 88d9b7be1de..a706b421975 100644 --- a/modules/lang-groovy/src/test/java/org/elasticsearch/script/groovy/GroovyScriptTests.java +++ b/modules/lang-groovy/src/test/java/org/elasticsearch/script/groovy/GroovyScriptTests.java @@ -26,7 +26,7 @@ import org.elasticsearch.common.lucene.search.function.CombineFunction; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService.ScriptType; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.search.sort.ScriptSortBuilder.ScriptSortType; import org.elasticsearch.search.sort.SortBuilders; diff --git a/modules/lang-groovy/src/test/java/org/elasticsearch/script/groovy/GroovySecurityTests.java b/modules/lang-groovy/src/test/java/org/elasticsearch/script/groovy/GroovySecurityTests.java index 31dc154a9e2..1ac31a70589 100644 --- a/modules/lang-groovy/src/test/java/org/elasticsearch/script/groovy/GroovySecurityTests.java +++ b/modules/lang-groovy/src/test/java/org/elasticsearch/script/groovy/GroovySecurityTests.java @@ -25,7 +25,7 @@ import org.codehaus.groovy.control.MultipleCompilationErrorsException; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.script.CompiledScript; import org.elasticsearch.script.ScriptException; -import org.elasticsearch.script.ScriptService; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.test.ESTestCase; import java.nio.file.Path; @@ -139,7 +139,7 @@ public class GroovySecurityTests extends ESTestCase { vars.put("myarray", Arrays.asList("foo")); vars.put("myobject", new MyObject()); - se.executable(new CompiledScript(ScriptService.ScriptType.INLINE, "test", "js", se.compile(null, script, Collections.emptyMap())), vars).run(); + se.executable(new CompiledScript(ScriptType.INLINE, "test", "js", se.compile(null, script, Collections.emptyMap())), vars).run(); } public static class MyObject { diff --git a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestRenderSearchTemplateAction.java b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestRenderSearchTemplateAction.java index 489d7f83f32..c41baae2e69 100644 --- a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestRenderSearchTemplateAction.java +++ b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestRenderSearchTemplateAction.java @@ -27,7 +27,7 @@ import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestActions; import org.elasticsearch.rest.action.RestToXContentListener; -import org.elasticsearch.script.ScriptService; +import org.elasticsearch.script.ScriptType; import java.io.IOException; @@ -53,7 +53,7 @@ public class RestRenderSearchTemplateAction extends BaseRestHandler { String id = request.param("id"); if (id != null) { - renderRequest.setScriptType(ScriptService.ScriptType.STORED); + renderRequest.setScriptType(ScriptType.STORED); renderRequest.setScript(id); } diff --git a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestSearchTemplateAction.java b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestSearchTemplateAction.java index 2feeb2d3280..ed6ed6a050b 100644 --- a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestSearchTemplateAction.java +++ b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestSearchTemplateAction.java @@ -40,7 +40,7 @@ import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestActions; import org.elasticsearch.rest.action.RestStatusToXContentListener; import org.elasticsearch.rest.action.search.RestSearchAction; -import org.elasticsearch.script.ScriptService; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.SearchRequestParsers; import java.io.IOException; @@ -57,17 +57,17 @@ public class RestSearchTemplateAction extends BaseRestHandler { request.setScriptParams(parser.map()) , new ParseField("params"), ObjectParser.ValueType.OBJECT); PARSER.declareString((request, s) -> { - request.setScriptType(ScriptService.ScriptType.FILE); + request.setScriptType(ScriptType.FILE); request.setScript(s); }, new ParseField("file")); PARSER.declareString((request, s) -> { - request.setScriptType(ScriptService.ScriptType.STORED); + request.setScriptType(ScriptType.STORED); request.setScript(s); }, new ParseField("id")); PARSER.declareBoolean(SearchTemplateRequest::setExplain, new ParseField("explain")); PARSER.declareBoolean(SearchTemplateRequest::setProfile, new ParseField("profile")); PARSER.declareField((parser, request, value) -> { - request.setScriptType(ScriptService.ScriptType.INLINE); + request.setScriptType(ScriptType.INLINE); if (parser.currentToken() == XContentParser.Token.START_OBJECT) { try (XContentBuilder builder = XContentFactory.contentBuilder(parser.contentType())) { request.setScript(builder.copyCurrentStructure(parser).bytes().utf8ToString()); diff --git a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/SearchTemplateRequest.java b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/SearchTemplateRequest.java index 1fa7f24de8f..249b0080775 100644 --- a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/SearchTemplateRequest.java +++ b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/SearchTemplateRequest.java @@ -27,7 +27,7 @@ import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.script.ScriptService; +import org.elasticsearch.script.ScriptType; import java.io.IOException; import java.util.Map; @@ -43,7 +43,7 @@ public class SearchTemplateRequest extends ActionRequest private boolean simulate = false; private boolean explain = false; private boolean profile = false; - private ScriptService.ScriptType scriptType; + private ScriptType scriptType; private String script; private Map scriptParams; @@ -87,11 +87,11 @@ public class SearchTemplateRequest extends ActionRequest this.profile = profile; } - public ScriptService.ScriptType getScriptType() { + public ScriptType getScriptType() { return scriptType; } - public void setScriptType(ScriptService.ScriptType scriptType) { + public void setScriptType(ScriptType scriptType) { this.scriptType = scriptType; } @@ -143,7 +143,7 @@ public class SearchTemplateRequest extends ActionRequest simulate = in.readBoolean(); explain = in.readBoolean(); profile = in.readBoolean(); - scriptType = ScriptService.ScriptType.readFrom(in); + scriptType = ScriptType.readFrom(in); script = in.readOptionalString(); if (in.readBoolean()) { scriptParams = in.readMap(); @@ -157,7 +157,7 @@ public class SearchTemplateRequest extends ActionRequest out.writeBoolean(simulate); out.writeBoolean(explain); out.writeBoolean(profile); - ScriptService.ScriptType.writeTo(scriptType, out); + ScriptType.writeTo(scriptType, out); out.writeOptionalString(script); boolean hasParams = scriptParams != null; out.writeBoolean(hasParams); diff --git a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/SearchTemplateRequestBuilder.java b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/SearchTemplateRequestBuilder.java index 52f51b7254f..02d27ac79fc 100644 --- a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/SearchTemplateRequestBuilder.java +++ b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/SearchTemplateRequestBuilder.java @@ -22,7 +22,7 @@ package org.elasticsearch.script.mustache; import org.elasticsearch.action.ActionRequestBuilder; import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.client.ElasticsearchClient; -import org.elasticsearch.script.ScriptService; +import org.elasticsearch.script.ScriptType; import java.util.Map; @@ -63,7 +63,7 @@ public class SearchTemplateRequestBuilder return this; } - public SearchTemplateRequestBuilder setScriptType(ScriptService.ScriptType scriptType) { + public SearchTemplateRequestBuilder setScriptType(ScriptType scriptType) { request.setScriptType(scriptType); return this; } diff --git a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/TemplateQueryBuilder.java b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/TemplateQueryBuilder.java index f81d5c7e053..731659c4b72 100644 --- a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/TemplateQueryBuilder.java +++ b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/TemplateQueryBuilder.java @@ -35,13 +35,10 @@ import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.index.query.QueryRewriteContext; import org.elasticsearch.index.query.QueryShardContext; -import org.elasticsearch.script.ExecutableScript; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptContext; -import org.elasticsearch.script.ScriptService; +import org.elasticsearch.script.ScriptType; import java.io.IOException; -import java.util.Collections; import java.util.Map; import java.util.Objects; import java.util.Optional; @@ -59,11 +56,11 @@ public class TemplateQueryBuilder extends AbstractQueryBuilder params) { + public TemplateQueryBuilder(String template, ScriptType scriptType, Map params) { this(new Script(template, scriptType, "mustache", params)); } - public TemplateQueryBuilder(String template, ScriptService.ScriptType scriptType, Map params, XContentType ct) { + public TemplateQueryBuilder(String template, ScriptType scriptType, Map params, XContentType ct) { this(new Script(template, scriptType, "mustache", params, ct)); } diff --git a/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/CustomMustacheFactoryTests.java b/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/CustomMustacheFactoryTests.java index fefa98e8f86..f2f0d6d80fd 100644 --- a/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/CustomMustacheFactoryTests.java +++ b/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/CustomMustacheFactoryTests.java @@ -31,7 +31,7 @@ import java.util.Map; import static java.util.Collections.emptyMap; import static java.util.Collections.singletonMap; -import static org.elasticsearch.script.ScriptService.ScriptType.INLINE; +import static org.elasticsearch.script.ScriptType.INLINE; import static org.elasticsearch.script.mustache.CustomMustacheFactory.CONTENT_TYPE_PARAM; import static org.elasticsearch.script.mustache.CustomMustacheFactory.JSON_MIME_TYPE; import static org.elasticsearch.script.mustache.CustomMustacheFactory.PLAIN_TEXT_MIME_TYPE; diff --git a/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/MultiSearchTemplateIT.java b/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/MultiSearchTemplateIT.java index f5d1a9dd791..91fc4db43dd 100644 --- a/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/MultiSearchTemplateIT.java +++ b/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/MultiSearchTemplateIT.java @@ -23,7 +23,7 @@ import org.elasticsearch.action.index.IndexRequestBuilder; import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.plugins.Plugin; -import org.elasticsearch.script.ScriptService; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.test.ESIntegTestCase; import java.util.Arrays; @@ -74,7 +74,7 @@ public class MultiSearchTemplateIT extends ESIntegTestCase { // Search #1 SearchTemplateRequest search1 = new SearchTemplateRequest(); search1.setRequest(new SearchRequest("msearch")); - search1.setScriptType(ScriptService.ScriptType.INLINE); + search1.setScriptType(ScriptType.INLINE); search1.setScript(template); Map params1 = new HashMap<>(); @@ -87,7 +87,7 @@ public class MultiSearchTemplateIT extends ESIntegTestCase { // Search #2 (Simulate is true) SearchTemplateRequest search2 = new SearchTemplateRequest(); search2.setRequest(new SearchRequest("msearch")); - search2.setScriptType(ScriptService.ScriptType.INLINE); + search2.setScriptType(ScriptType.INLINE); search2.setScript(template); search2.setSimulate(true); @@ -101,7 +101,7 @@ public class MultiSearchTemplateIT extends ESIntegTestCase { // Search #3 SearchTemplateRequest search3 = new SearchTemplateRequest(); search3.setRequest(new SearchRequest("msearch")); - search3.setScriptType(ScriptService.ScriptType.INLINE); + search3.setScriptType(ScriptType.INLINE); search3.setScript(template); search3.setSimulate(false); @@ -115,7 +115,7 @@ public class MultiSearchTemplateIT extends ESIntegTestCase { // Search #4 (Fail because of unknown index) SearchTemplateRequest search4 = new SearchTemplateRequest(); search4.setRequest(new SearchRequest("unknown")); - search4.setScriptType(ScriptService.ScriptType.INLINE); + search4.setScriptType(ScriptType.INLINE); search4.setScript(template); Map params4 = new HashMap<>(); @@ -128,7 +128,7 @@ public class MultiSearchTemplateIT extends ESIntegTestCase { // Search #5 (Simulate is true) SearchTemplateRequest search5 = new SearchTemplateRequest(); search5.setRequest(new SearchRequest("msearch")); - search5.setScriptType(ScriptService.ScriptType.INLINE); + search5.setScriptType(ScriptType.INLINE); search5.setScript("{{! ignore me }}{\"query\":{\"terms\":{\"group\":[{{#groups}}{{.}},{{/groups}}]}}}"); search5.setSimulate(true); diff --git a/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/MultiSearchTemplateRequestTests.java b/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/MultiSearchTemplateRequestTests.java index d7807c1a268..e3b633006c5 100644 --- a/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/MultiSearchTemplateRequestTests.java +++ b/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/MultiSearchTemplateRequestTests.java @@ -21,7 +21,7 @@ package org.elasticsearch.script.mustache; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.rest.RestRequest; -import org.elasticsearch.script.ScriptService; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.StreamsUtils; import org.elasticsearch.test.rest.FakeRestRequest; @@ -58,9 +58,9 @@ public class MultiSearchTemplateRequestTests extends ESTestCase { assertNotNull(request.requests().get(1).getScript()); assertNotNull(request.requests().get(2).getScript()); - assertEquals(ScriptService.ScriptType.INLINE, request.requests().get(0).getScriptType()); - assertEquals(ScriptService.ScriptType.INLINE, request.requests().get(1).getScriptType()); - assertEquals(ScriptService.ScriptType.INLINE, request.requests().get(2).getScriptType()); + assertEquals(ScriptType.INLINE, request.requests().get(0).getScriptType()); + assertEquals(ScriptType.INLINE, request.requests().get(1).getScriptType()); + assertEquals(ScriptType.INLINE, request.requests().get(2).getScriptType()); assertEquals("{\"query\":{\"match_{{template}}\":{}}}", request.requests().get(0).getScript()); assertEquals("{\"query\":{\"match_{{template}}\":{}}}", request.requests().get(1).getScript()); assertEquals("{\"query\":{\"match_{{template}}\":{}}}", request.requests().get(2).getScript()); diff --git a/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/MustacheScriptEngineTests.java b/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/MustacheScriptEngineTests.java index b9f596e4d3d..ca4a6de7166 100644 --- a/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/MustacheScriptEngineTests.java +++ b/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/MustacheScriptEngineTests.java @@ -27,7 +27,7 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.script.CompiledScript; import org.elasticsearch.script.ExecutableScript; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.test.ESTestCase; import org.junit.Before; @@ -59,7 +59,7 @@ public class MustacheScriptEngineTests extends ESTestCase { + "\"negative\": {\"term\": {\"body\": {\"value\": \"solr\"}" + "}}, \"negative_boost\": {{boost_val}} } }}"; Map vars = new HashMap<>(); vars.put("boost_val", "0.3"); - BytesReference o = (BytesReference) qe.executable(new CompiledScript(ScriptService.ScriptType.INLINE, "", "mustache", + BytesReference o = (BytesReference) qe.executable(new CompiledScript(ScriptType.INLINE, "", "mustache", qe.compile(null, template, compileParams)), vars).run(); assertEquals("GET _search {\"query\": {\"boosting\": {\"positive\": {\"match\": {\"body\": \"gift\"}}," + "\"negative\": {\"term\": {\"body\": {\"value\": \"solr\"}}}, \"negative_boost\": 0.3 } }}", @@ -71,7 +71,7 @@ public class MustacheScriptEngineTests extends ESTestCase { Map vars = new HashMap<>(); vars.put("boost_val", "0.3"); vars.put("body_val", "\"quick brown\""); - BytesReference o = (BytesReference) qe.executable(new CompiledScript(ScriptService.ScriptType.INLINE, "", "mustache", + BytesReference o = (BytesReference) qe.executable(new CompiledScript(ScriptType.INLINE, "", "mustache", qe.compile(null, template, compileParams)), vars).run(); assertEquals("GET _search {\"query\": {\"boosting\": {\"positive\": {\"match\": {\"body\": \"gift\"}}," + "\"negative\": {\"term\": {\"body\": {\"value\": \"\\\"quick brown\\\"\"}}}, \"negative_boost\": 0.3 } }}", @@ -83,7 +83,7 @@ public class MustacheScriptEngineTests extends ESTestCase { String templateString = "{" + "\"inline\":{\"match_{{template}}\": {}}," + "\"params\":{\"template\":\"all\"}" + "}"; XContentParser parser = XContentFactory.xContent(templateString).createParser(templateString); Script script = Script.parse(parser, new ParseFieldMatcher(false)); - CompiledScript compiledScript = new CompiledScript(ScriptService.ScriptType.INLINE, null, "mustache", + CompiledScript compiledScript = new CompiledScript(ScriptType.INLINE, null, "mustache", qe.compile(null, script.getScript(), Collections.emptyMap())); ExecutableScript executableScript = qe.executable(compiledScript, script.getParams()); assertThat(((BytesReference) executableScript.run()).utf8ToString(), equalTo("{\"match_all\":{}}")); @@ -94,7 +94,7 @@ public class MustacheScriptEngineTests extends ESTestCase { + " \"template\":\"all\"," + " \"use_it\": true" + " }" + "}"; XContentParser parser = XContentFactory.xContent(templateString).createParser(templateString); Script script = Script.parse(parser, new ParseFieldMatcher(false)); - CompiledScript compiledScript = new CompiledScript(ScriptService.ScriptType.INLINE, null, "mustache", + CompiledScript compiledScript = new CompiledScript(ScriptType.INLINE, null, "mustache", qe.compile(null, script.getScript(), Collections.emptyMap())); ExecutableScript executableScript = qe.executable(compiledScript, script.getParams()); assertThat(((BytesReference) executableScript.run()).utf8ToString(), equalTo("{ \"match_all\":{} }")); diff --git a/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/MustacheTests.java b/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/MustacheTests.java index becdda0e592..ba19febfd21 100644 --- a/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/MustacheTests.java +++ b/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/MustacheTests.java @@ -44,7 +44,7 @@ import java.util.Set; import static java.util.Collections.singleton; import static java.util.Collections.singletonMap; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; -import static org.elasticsearch.script.ScriptService.ScriptType.INLINE; +import static org.elasticsearch.script.ScriptType.INLINE; import static org.hamcrest.Matchers.both; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; diff --git a/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/SearchTemplateIT.java b/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/SearchTemplateIT.java index c3656029bc4..fb67c561b83 100644 --- a/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/SearchTemplateIT.java +++ b/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/SearchTemplateIT.java @@ -25,8 +25,7 @@ import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.plugins.Plugin; -import org.elasticsearch.script.ScriptService; -import org.elasticsearch.script.ScriptService.ScriptType; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.test.ESSingleNodeTestCase; import org.junit.Before; @@ -269,14 +268,14 @@ public class SearchTemplateIT extends ESSingleNodeTestCase { templateParams.put("fieldParam", "bar"); searchResponse = new SearchTemplateRequestBuilder(client()) .setRequest(new SearchRequest("test").types("type")) - .setScript("/mustache/2").setScriptType(ScriptService.ScriptType.STORED).setScriptParams(templateParams) + .setScript("/mustache/2").setScriptType(ScriptType.STORED).setScriptParams(templateParams) .get(); assertHitCount(searchResponse.getResponse(), 1); Map vars = new HashMap<>(); vars.put("fieldParam", "bar"); - TemplateQueryBuilder builder = new TemplateQueryBuilder("3", ScriptService.ScriptType.STORED, vars); + TemplateQueryBuilder builder = new TemplateQueryBuilder("3", ScriptType.STORED, vars); SearchResponse sr = client().prepareSearch().setQuery(builder) .execute().actionGet(); assertHitCount(sr, 1); @@ -309,7 +308,7 @@ public class SearchTemplateIT extends ESSingleNodeTestCase { ParsingException e = expectThrows(ParsingException.class, () -> new SearchTemplateRequestBuilder(client()) .setRequest(new SearchRequest("testindex").types("test")) - .setScript("git01").setScriptType(ScriptService.ScriptType.STORED).setScriptParams(templateParams) + .setScript("git01").setScriptType(ScriptType.STORED).setScriptParams(templateParams) .get()); assertThat(e.getMessage(), containsString("[match] query does not support type ooophrase_prefix")); @@ -321,7 +320,7 @@ public class SearchTemplateIT extends ESSingleNodeTestCase { SearchTemplateResponse searchResponse = new SearchTemplateRequestBuilder(client()) .setRequest(new SearchRequest("testindex").types("test")) - .setScript("git01").setScriptType(ScriptService.ScriptType.STORED).setScriptParams(templateParams) + .setScript("git01").setScriptType(ScriptType.STORED).setScriptParams(templateParams) .get(); assertHitCount(searchResponse.getResponse(), 1); } @@ -350,7 +349,7 @@ public class SearchTemplateIT extends ESSingleNodeTestCase { SearchTemplateResponse searchResponse = new SearchTemplateRequestBuilder(client()) .setRequest(new SearchRequest("test").types("type")) - .setScript("/mustache/4").setScriptType(ScriptService.ScriptType.STORED).setScriptParams(arrayTemplateParams) + .setScript("/mustache/4").setScriptType(ScriptType.STORED).setScriptParams(arrayTemplateParams) .get(); assertHitCount(searchResponse.getResponse(), 5); } diff --git a/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/SearchTemplateRequestTests.java b/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/SearchTemplateRequestTests.java index b5831a3c5a8..528f87f1dd2 100644 --- a/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/SearchTemplateRequestTests.java +++ b/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/SearchTemplateRequestTests.java @@ -22,7 +22,7 @@ package org.elasticsearch.script.mustache; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; -import org.elasticsearch.script.ScriptService; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.test.ESTestCase; import java.util.List; @@ -52,7 +52,7 @@ public class SearchTemplateRequestTests extends ESTestCase { SearchTemplateRequest request = RestSearchTemplateAction.parse(newBytesReference(source)); assertThat(request.getScript(), equalTo("{\"query\":{\"terms\":{\"status\":[\"{{#status}}\",\"{{.}}\",\"{{/status}}\"]}}}")); - assertThat(request.getScriptType(), equalTo(ScriptService.ScriptType.INLINE)); + assertThat(request.getScriptType(), equalTo(ScriptType.INLINE)); assertThat(request.getScriptParams(), nullValue()); } @@ -71,7 +71,7 @@ public class SearchTemplateRequestTests extends ESTestCase { SearchTemplateRequest request = RestSearchTemplateAction.parse(newBytesReference(source)); assertThat(request.getScript(), equalTo("{\"query\":{\"match\":{\"{{my_field}}\":\"{{my_value}}\"}},\"size\":\"{{my_size}}\"}")); - assertThat(request.getScriptType(), equalTo(ScriptService.ScriptType.INLINE)); + assertThat(request.getScriptType(), equalTo(ScriptType.INLINE)); assertThat(request.getScriptParams().size(), equalTo(3)); assertThat(request.getScriptParams(), hasEntry("my_field", "foo")); assertThat(request.getScriptParams(), hasEntry("my_value", "bar")); @@ -83,7 +83,7 @@ public class SearchTemplateRequestTests extends ESTestCase { SearchTemplateRequest request = RestSearchTemplateAction.parse(newBytesReference(source)); assertThat(request.getScript(), equalTo("{\"query\":{\"bool\":{\"must\":{\"match\":{\"foo\":\"{{text}}\"}}}}}")); - assertThat(request.getScriptType(), equalTo(ScriptService.ScriptType.INLINE)); + assertThat(request.getScriptType(), equalTo(ScriptType.INLINE)); assertThat(request.getScriptParams(), nullValue()); } @@ -94,7 +94,7 @@ public class SearchTemplateRequestTests extends ESTestCase { SearchTemplateRequest request = RestSearchTemplateAction.parse(newBytesReference(source)); assertThat(request.getScript(), equalTo("{\"query\":{\"match\":{\"{{field}}\":\"{{value}}\"}}}")); - assertThat(request.getScriptType(), equalTo(ScriptService.ScriptType.INLINE)); + assertThat(request.getScriptType(), equalTo(ScriptType.INLINE)); assertThat(request.getScriptParams().size(), equalTo(1)); assertThat(request.getScriptParams(), hasKey("status")); assertThat((List) request.getScriptParams().get("status"), hasItems("pending", "published")); @@ -105,7 +105,7 @@ public class SearchTemplateRequestTests extends ESTestCase { SearchTemplateRequest request = RestSearchTemplateAction.parse(newBytesReference(source)); assertThat(request.getScript(), equalTo("fileTemplate")); - assertThat(request.getScriptType(), equalTo(ScriptService.ScriptType.FILE)); + assertThat(request.getScriptType(), equalTo(ScriptType.FILE)); assertThat(request.getScriptParams(), nullValue()); } @@ -114,7 +114,7 @@ public class SearchTemplateRequestTests extends ESTestCase { SearchTemplateRequest request = RestSearchTemplateAction.parse(newBytesReference(source)); assertThat(request.getScript(), equalTo("template_foo")); - assertThat(request.getScriptType(), equalTo(ScriptService.ScriptType.FILE)); + assertThat(request.getScriptType(), equalTo(ScriptType.FILE)); assertThat(request.getScriptParams().size(), equalTo(2)); assertThat(request.getScriptParams(), hasEntry("foo", "bar")); assertThat(request.getScriptParams(), hasEntry("size", 500)); @@ -125,7 +125,7 @@ public class SearchTemplateRequestTests extends ESTestCase { SearchTemplateRequest request = RestSearchTemplateAction.parse(newBytesReference(source)); assertThat(request.getScript(), equalTo("storedTemplate")); - assertThat(request.getScriptType(), equalTo(ScriptService.ScriptType.STORED)); + assertThat(request.getScriptType(), equalTo(ScriptType.STORED)); assertThat(request.getScriptParams(), nullValue()); } @@ -134,7 +134,7 @@ public class SearchTemplateRequestTests extends ESTestCase { SearchTemplateRequest request = RestSearchTemplateAction.parse(newBytesReference(source)); assertThat(request.getScript(), equalTo("another_template")); - assertThat(request.getScriptType(), equalTo(ScriptService.ScriptType.STORED)); + assertThat(request.getScriptType(), equalTo(ScriptType.STORED)); assertThat(request.getScriptParams().size(), equalTo(1)); assertThat(request.getScriptParams(), hasEntry("bar", "foo")); } diff --git a/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/TemplateQueryBuilderTests.java b/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/TemplateQueryBuilderTests.java index 919a0a2cbb4..9348085ec78 100644 --- a/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/TemplateQueryBuilderTests.java +++ b/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/TemplateQueryBuilderTests.java @@ -36,7 +36,7 @@ import org.elasticsearch.index.query.TermQueryBuilder; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.MockScriptPlugin; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService.ScriptType; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.internal.SearchContext; import org.elasticsearch.test.AbstractQueryTestCase; import org.junit.Before; diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/NeedsScoreTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/NeedsScoreTests.java index 3fe071c5221..2de25ba54b0 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/NeedsScoreTests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/NeedsScoreTests.java @@ -22,7 +22,7 @@ package org.elasticsearch.painless; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.IndexService; import org.elasticsearch.script.CompiledScript; -import org.elasticsearch.script.ScriptService.ScriptType; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.script.SearchScript; import org.elasticsearch.search.lookup.SearchLookup; import org.elasticsearch.test.ESSingleNodeTestCase; diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/ScriptEngineTests.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/ScriptEngineTests.java index 2cd21c0596f..89385c8862c 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/ScriptEngineTests.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/ScriptEngineTests.java @@ -21,7 +21,7 @@ package org.elasticsearch.painless; import org.elasticsearch.script.CompiledScript; import org.elasticsearch.script.ExecutableScript; -import org.elasticsearch.script.ScriptService; +import org.elasticsearch.script.ScriptType; import java.util.Arrays; import java.util.Collections; @@ -83,7 +83,7 @@ public class ScriptEngineTests extends ScriptTestCase { Object compiledScript = scriptEngine.compile(null, "return ctx.value;", Collections.emptyMap()); - ExecutableScript script = scriptEngine.executable(new CompiledScript(ScriptService.ScriptType.INLINE, + ExecutableScript script = scriptEngine.executable(new CompiledScript(ScriptType.INLINE, "testChangingVarsCrossExecution1", "painless", compiledScript), vars); ctx.put("value", 1); @@ -99,7 +99,7 @@ public class ScriptEngineTests extends ScriptTestCase { Map vars = new HashMap<>(); Object compiledScript = scriptEngine.compile(null, "return params['value'];", Collections.emptyMap()); - ExecutableScript script = scriptEngine.executable(new CompiledScript(ScriptService.ScriptType.INLINE, + ExecutableScript script = scriptEngine.executable(new CompiledScript(ScriptType.INLINE, "testChangingVarsCrossExecution2", "painless", compiledScript), vars); script.setNextVar("value", 1); diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/ScriptTestCase.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/ScriptTestCase.java index 672204cbc25..10149674bea 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/ScriptTestCase.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/ScriptTestCase.java @@ -26,7 +26,7 @@ import org.elasticsearch.painless.antlr.Walker; import org.elasticsearch.script.CompiledScript; import org.elasticsearch.script.ExecutableScript; import org.elasticsearch.script.ScriptException; -import org.elasticsearch.script.ScriptService; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.test.ESTestCase; import org.junit.Before; @@ -83,7 +83,7 @@ public abstract class ScriptTestCase extends ESTestCase { } // test actual script execution Object object = scriptEngine.compile(null, script, compileParams); - CompiledScript compiled = new CompiledScript(ScriptService.ScriptType.INLINE, getTestName(), "painless", object); + CompiledScript compiled = new CompiledScript(ScriptType.INLINE, getTestName(), "painless", object); ExecutableScript executableScript = scriptEngine.executable(compiled, vars); if (scorer != null) { ((ScorerAware)executableScript).setScorer(scorer); diff --git a/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorQuerySearchIT.java b/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorQuerySearchIT.java index 828f800f34e..d0ba6afbdab 100644 --- a/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorQuerySearchIT.java +++ b/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorQuerySearchIT.java @@ -34,7 +34,7 @@ import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.MockScriptPlugin; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder; import org.elasticsearch.search.sort.SortOrder; import org.elasticsearch.test.ESSingleNodeTestCase; @@ -42,7 +42,6 @@ import org.elasticsearch.test.ESSingleNodeTestCase; import java.io.IOException; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.function.Function; @@ -90,7 +89,7 @@ public class PercolatorQuerySearchIT extends ESSingleNodeTestCase { ensureGreen(); client().prepareIndex("index", "type", "1") .setSource(jsonBuilder().startObject().field("query", QueryBuilders.scriptQuery( - new Script("1==1", ScriptService.ScriptType.INLINE, CustomScriptPlugin.NAME, null))).endObject()) + new Script("1==1", ScriptType.INLINE, CustomScriptPlugin.NAME, null))).endObject()) .setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE) .execute().actionGet(); PercolateResponse response = preparePercolate(client()) diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestUpdateByQueryAction.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestUpdateByQueryAction.java index 8fe9cec14b7..176ba49901c 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestUpdateByQueryAction.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestUpdateByQueryAction.java @@ -29,7 +29,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.SearchRequestParsers; import java.io.IOException; @@ -79,7 +79,7 @@ public class RestUpdateByQueryAction extends AbstractBulkByQueryRestHandler config, ParseFieldMatcher parseFieldMatcher) { String script = null; - ScriptService.ScriptType type = null; + ScriptType type = null; String lang = null; Map params = null; for (Iterator> itr = config.entrySet().iterator(); itr.hasNext();) { @@ -98,24 +98,24 @@ public class RestUpdateByQueryAction extends AbstractBulkByQueryRestHandler vars = new HashMap(); - Object o = se.executable(new CompiledScript(ScriptService.ScriptType.INLINE, "testSimpleEquation", "js", se.compile(null, "1 + 2", Collections.emptyMap())), vars).run(); + Object o = se.executable(new CompiledScript(ScriptType.INLINE, "testSimpleEquation", "js", se.compile(null, "1 + 2", Collections.emptyMap())), vars).run(); assertThat(((Number) o).intValue(), equalTo(3)); } public void testNullVars() { - CompiledScript script = new CompiledScript(ScriptService.ScriptType.INLINE, "testSimpleEquation", "js", + CompiledScript script = new CompiledScript(ScriptType.INLINE, "testSimpleEquation", "js", se.compile(null, "1 + 2", emptyMap())); Object o = se.executable(script, null).run(); assertThat(((Number) o).intValue(), equalTo(3)); @@ -72,20 +72,20 @@ public class JavaScriptScriptEngineTests extends ESTestCase { Map obj2 = MapBuilder.newMapBuilder().put("prop2", "value2").map(); Map obj1 = MapBuilder.newMapBuilder().put("prop1", "value1").put("obj2", obj2).put("l", Arrays.asList("2", "1")).map(); vars.put("obj1", obj1); - Object o = se.executable(new CompiledScript(ScriptService.ScriptType.INLINE, "testMapAccess", "js", se.compile(null, "obj1", Collections.emptyMap())), vars).run(); + Object o = se.executable(new CompiledScript(ScriptType.INLINE, "testMapAccess", "js", se.compile(null, "obj1", Collections.emptyMap())), vars).run(); assertThat(o, instanceOf(Map.class)); obj1 = (Map) o; assertThat((String) obj1.get("prop1"), equalTo("value1")); assertThat((String) ((Map) obj1.get("obj2")).get("prop2"), equalTo("value2")); - o = se.executable(new CompiledScript(ScriptService.ScriptType.INLINE, "testMapAccess", "js", se.compile(null, "obj1.l[0]", Collections.emptyMap())), vars).run(); + o = se.executable(new CompiledScript(ScriptType.INLINE, "testMapAccess", "js", se.compile(null, "obj1.l[0]", Collections.emptyMap())), vars).run(); assertThat(((String) o), equalTo("2")); } @SuppressWarnings("unchecked") public void testJavaScriptObjectToMap() { Map vars = new HashMap(); - Object o = se.executable(new CompiledScript(ScriptService.ScriptType.INLINE, "testJavaScriptObjectToMap", "js", + Object o = se.executable(new CompiledScript(ScriptType.INLINE, "testJavaScriptObjectToMap", "js", se.compile(null, "var obj1 = {}; obj1.prop1 = 'value1'; obj1.obj2 = {}; obj1.obj2.prop2 = 'value2'; obj1", Collections.emptyMap())), vars).run(); Map obj1 = (Map) o; assertThat((String) obj1.get("prop1"), equalTo("value1")); @@ -101,7 +101,7 @@ public class JavaScriptScriptEngineTests extends ESTestCase { ctx.put("obj1", obj1); vars.put("ctx", ctx); - ExecutableScript executable = se.executable(new CompiledScript(ScriptService.ScriptType.INLINE, "testJavaScriptObjectMapInter", "js", + ExecutableScript executable = se.executable(new CompiledScript(ScriptType.INLINE, "testJavaScriptObjectMapInter", "js", se.compile(null, "ctx.obj2 = {}; ctx.obj2.prop2 = 'value2'; ctx.obj1.prop1 = 'uvalue1'", Collections.emptyMap())), vars); executable.run(); ctx = (Map) executable.unwrap(vars.get("ctx")); @@ -118,7 +118,7 @@ public class JavaScriptScriptEngineTests extends ESTestCase { ctx.put("doc", doc); Object compiled = se.compile(null, "ctx.doc.field1 = ['value1', 'value2']", Collections.emptyMap()); - ExecutableScript script = se.executable(new CompiledScript(ScriptService.ScriptType.INLINE, "testJavaScriptInnerArrayCreation", "js", + ExecutableScript script = se.executable(new CompiledScript(ScriptType.INLINE, "testJavaScriptInnerArrayCreation", "js", compiled), new HashMap()); script.setNextVar("ctx", ctx); script.run(); @@ -135,21 +135,21 @@ public class JavaScriptScriptEngineTests extends ESTestCase { Map obj1 = MapBuilder.newMapBuilder().put("prop1", "value1").put("obj2", obj2).map(); vars.put("l", Arrays.asList("1", "2", "3", obj1)); - Object o = se.executable(new CompiledScript(ScriptService.ScriptType.INLINE, "testAccessInScript", "js", + Object o = se.executable(new CompiledScript(ScriptType.INLINE, "testAccessInScript", "js", se.compile(null, "l.length", Collections.emptyMap())), vars).run(); assertThat(((Number) o).intValue(), equalTo(4)); - o = se.executable(new CompiledScript(ScriptService.ScriptType.INLINE, "testAccessInScript", "js", + o = se.executable(new CompiledScript(ScriptType.INLINE, "testAccessInScript", "js", se.compile(null, "l[0]", Collections.emptyMap())), vars).run(); assertThat(((String) o), equalTo("1")); - o = se.executable(new CompiledScript(ScriptService.ScriptType.INLINE, "testAccessInScript", "js", + o = se.executable(new CompiledScript(ScriptType.INLINE, "testAccessInScript", "js", se.compile(null, "l[3]", Collections.emptyMap())), vars).run(); obj1 = (Map) o; assertThat((String) obj1.get("prop1"), equalTo("value1")); assertThat((String) ((Map) obj1.get("obj2")).get("prop2"), equalTo("value2")); - o = se.executable(new CompiledScript(ScriptService.ScriptType.INLINE, "testAccessInScript", "js", + o = se.executable(new CompiledScript(ScriptType.INLINE, "testAccessInScript", "js", se.compile(null, "l[3].prop1", Collections.emptyMap())), vars).run(); assertThat(((String) o), equalTo("value1")); } @@ -160,7 +160,7 @@ public class JavaScriptScriptEngineTests extends ESTestCase { vars.put("ctx", ctx); Object compiledScript = se.compile(null, "ctx.value", Collections.emptyMap()); - ExecutableScript script = se.executable(new CompiledScript(ScriptService.ScriptType.INLINE, "testChangingVarsCrossExecution1", "js", + ExecutableScript script = se.executable(new CompiledScript(ScriptType.INLINE, "testChangingVarsCrossExecution1", "js", compiledScript), vars); ctx.put("value", 1); Object o = script.run(); @@ -175,7 +175,7 @@ public class JavaScriptScriptEngineTests extends ESTestCase { Map vars = new HashMap(); Object compiledScript = se.compile(null, "value", Collections.emptyMap()); - ExecutableScript script = se.executable(new CompiledScript(ScriptService.ScriptType.INLINE, "testChangingVarsCrossExecution2", "js", + ExecutableScript script = se.executable(new CompiledScript(ScriptType.INLINE, "testChangingVarsCrossExecution2", "js", compiledScript), vars); script.setNextVar("value", 1); Object o = script.run(); diff --git a/plugins/lang-javascript/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptMultiThreadedTests.java b/plugins/lang-javascript/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptMultiThreadedTests.java index c3614952ecf..a6ce1c95a20 100644 --- a/plugins/lang-javascript/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptMultiThreadedTests.java +++ b/plugins/lang-javascript/src/test/java/org/elasticsearch/script/javascript/JavaScriptScriptMultiThreadedTests.java @@ -23,7 +23,7 @@ import org.elasticsearch.common.Randomness; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.script.CompiledScript; import org.elasticsearch.script.ExecutableScript; -import org.elasticsearch.script.ScriptService; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.test.ESTestCase; import java.util.Collections; @@ -56,7 +56,7 @@ public class JavaScriptScriptMultiThreadedTests extends ESTestCase { Map vars = new HashMap(); vars.put("x", x); vars.put("y", y); - ExecutableScript script = se.executable(new CompiledScript(ScriptService.ScriptType.INLINE, "testExecutableNoRuntimeParams", "js", compiled), vars); + ExecutableScript script = se.executable(new CompiledScript(ScriptType.INLINE, "testExecutableNoRuntimeParams", "js", compiled), vars); for (int i = 0; i < between(100, 1000); i++) { long result = ((Number) script.run()).longValue(); assertThat(result, equalTo(addition)); @@ -95,7 +95,7 @@ public class JavaScriptScriptMultiThreadedTests extends ESTestCase { long x = Randomness.get().nextInt(); Map vars = new HashMap(); vars.put("x", x); - ExecutableScript script = se.executable(new CompiledScript(ScriptService.ScriptType.INLINE, "testExecutableNoRuntimeParams", "js", compiled), vars); + ExecutableScript script = se.executable(new CompiledScript(ScriptType.INLINE, "testExecutableNoRuntimeParams", "js", compiled), vars); for (int i = 0; i < between(100, 1000); i++) { long y = Randomness.get().nextInt(); long addition = x + y; @@ -141,7 +141,7 @@ public class JavaScriptScriptMultiThreadedTests extends ESTestCase { long addition = x + y; runtimeVars.put("x", x); runtimeVars.put("y", y); - long result = ((Number) se.executable(new CompiledScript(ScriptService.ScriptType.INLINE, "testExecutableNoRuntimeParams", "js", compiled), runtimeVars).run()).longValue(); + long result = ((Number) se.executable(new CompiledScript(ScriptType.INLINE, "testExecutableNoRuntimeParams", "js", compiled), runtimeVars).run()).longValue(); assertThat(result, equalTo(addition)); } } catch (Exception e) { diff --git a/plugins/lang-javascript/src/test/java/org/elasticsearch/script/javascript/JavaScriptSecurityTests.java b/plugins/lang-javascript/src/test/java/org/elasticsearch/script/javascript/JavaScriptSecurityTests.java index c1eb77d4e20..3928627840a 100644 --- a/plugins/lang-javascript/src/test/java/org/elasticsearch/script/javascript/JavaScriptSecurityTests.java +++ b/plugins/lang-javascript/src/test/java/org/elasticsearch/script/javascript/JavaScriptSecurityTests.java @@ -21,7 +21,7 @@ package org.elasticsearch.script.javascript; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.script.CompiledScript; -import org.elasticsearch.script.ScriptService; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.test.ESTestCase; import org.mozilla.javascript.EcmaError; import org.mozilla.javascript.WrappedException; @@ -54,7 +54,7 @@ public class JavaScriptSecurityTests extends ESTestCase { /** runs a script */ private void doTest(String script) { Map vars = new HashMap(); - se.executable(new CompiledScript(ScriptService.ScriptType.INLINE, "test", "js", se.compile(null, script, Collections.emptyMap())), vars).run(); + se.executable(new CompiledScript(ScriptType.INLINE, "test", "js", se.compile(null, script, Collections.emptyMap())), vars).run(); } /** asserts that a script runs without exception */ diff --git a/plugins/lang-python/src/test/java/org/elasticsearch/script/python/PythonScriptEngineTests.java b/plugins/lang-python/src/test/java/org/elasticsearch/script/python/PythonScriptEngineTests.java index 7d771db3051..f3bdd75a09a 100644 --- a/plugins/lang-python/src/test/java/org/elasticsearch/script/python/PythonScriptEngineTests.java +++ b/plugins/lang-python/src/test/java/org/elasticsearch/script/python/PythonScriptEngineTests.java @@ -28,7 +28,7 @@ import org.elasticsearch.common.collect.MapBuilder; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.script.CompiledScript; import org.elasticsearch.script.ExecutableScript; -import org.elasticsearch.script.ScriptService; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.test.ESTestCase; import org.junit.After; import org.junit.Before; @@ -51,7 +51,7 @@ public class PythonScriptEngineTests extends ESTestCase { public void testSimpleEquation() { Map vars = new HashMap(); - Object o = se.executable(new CompiledScript(ScriptService.ScriptType.INLINE, "testSimpleEquation", "python", se.compile(null, "1 + 2", Collections.emptyMap())), vars).run(); + Object o = se.executable(new CompiledScript(ScriptType.INLINE, "testSimpleEquation", "python", se.compile(null, "1 + 2", Collections.emptyMap())), vars).run(); assertThat(((Number) o).intValue(), equalTo(3)); } @@ -62,13 +62,13 @@ public class PythonScriptEngineTests extends ESTestCase { Map obj2 = MapBuilder.newMapBuilder().put("prop2", "value2").map(); Map obj1 = MapBuilder.newMapBuilder().put("prop1", "value1").put("obj2", obj2).put("l", Arrays.asList("2", "1")).map(); vars.put("obj1", obj1); - Object o = se.executable(new CompiledScript(ScriptService.ScriptType.INLINE, "testMapAccess", "python", se.compile(null, "obj1", Collections.emptyMap())), vars).run(); + Object o = se.executable(new CompiledScript(ScriptType.INLINE, "testMapAccess", "python", se.compile(null, "obj1", Collections.emptyMap())), vars).run(); assertThat(o, instanceOf(Map.class)); obj1 = (Map) o; assertThat((String) obj1.get("prop1"), equalTo("value1")); assertThat((String) ((Map) obj1.get("obj2")).get("prop2"), equalTo("value2")); - o = se.executable(new CompiledScript(ScriptService.ScriptType.INLINE, "testMapAccess", "python", se.compile(null, "obj1['l'][0]", Collections.emptyMap())), vars).run(); + o = se.executable(new CompiledScript(ScriptType.INLINE, "testMapAccess", "python", se.compile(null, "obj1['l'][0]", Collections.emptyMap())), vars).run(); assertThat(((String) o), equalTo("2")); } @@ -81,7 +81,7 @@ public class PythonScriptEngineTests extends ESTestCase { ctx.put("obj1", obj1); vars.put("ctx", ctx); - ExecutableScript executable = se.executable(new CompiledScript(ScriptService.ScriptType.INLINE, "testObjectInterMap", "python", + ExecutableScript executable = se.executable(new CompiledScript(ScriptType.INLINE, "testObjectInterMap", "python", se.compile(null, "ctx['obj2'] = { 'prop2' : 'value2' }; ctx['obj1']['prop1'] = 'uvalue1'", Collections.emptyMap())), vars); executable.run(); ctx = (Map) executable.unwrap(vars.get("ctx")); @@ -101,15 +101,15 @@ public class PythonScriptEngineTests extends ESTestCase { // Object o = se.execute(se.compile("l.length"), vars); // assertThat(((Number) o).intValue(), equalTo(4)); - Object o = se.executable(new CompiledScript(ScriptService.ScriptType.INLINE, "testAccessListInScript", "python", se.compile(null, "l[0]", Collections.emptyMap())), vars).run(); + Object o = se.executable(new CompiledScript(ScriptType.INLINE, "testAccessListInScript", "python", se.compile(null, "l[0]", Collections.emptyMap())), vars).run(); assertThat(((String) o), equalTo("1")); - o = se.executable(new CompiledScript(ScriptService.ScriptType.INLINE, "testAccessListInScript", "python", se.compile(null, "l[3]", Collections.emptyMap())), vars).run(); + o = se.executable(new CompiledScript(ScriptType.INLINE, "testAccessListInScript", "python", se.compile(null, "l[3]", Collections.emptyMap())), vars).run(); obj1 = (Map) o; assertThat((String) obj1.get("prop1"), equalTo("value1")); assertThat((String) ((Map) obj1.get("obj2")).get("prop2"), equalTo("value2")); - o = se.executable(new CompiledScript(ScriptService.ScriptType.INLINE, "testAccessListInScript", "python", se.compile(null, "l[3]['prop1']", Collections.emptyMap())), vars).run(); + o = se.executable(new CompiledScript(ScriptType.INLINE, "testAccessListInScript", "python", se.compile(null, "l[3]['prop1']", Collections.emptyMap())), vars).run(); assertThat(((String) o), equalTo("value1")); } @@ -119,7 +119,7 @@ public class PythonScriptEngineTests extends ESTestCase { vars.put("ctx", ctx); Object compiledScript = se.compile(null, "ctx['value']", Collections.emptyMap()); - ExecutableScript script = se.executable(new CompiledScript(ScriptService.ScriptType.INLINE, "testChangingVarsCrossExecution1", "python", compiledScript), vars); + ExecutableScript script = se.executable(new CompiledScript(ScriptType.INLINE, "testChangingVarsCrossExecution1", "python", compiledScript), vars); ctx.put("value", 1); Object o = script.run(); assertThat(((Number) o).intValue(), equalTo(1)); @@ -134,7 +134,7 @@ public class PythonScriptEngineTests extends ESTestCase { Map ctx = new HashMap(); Object compiledScript = se.compile(null, "value", Collections.emptyMap()); - ExecutableScript script = se.executable(new CompiledScript(ScriptService.ScriptType.INLINE, "testChangingVarsCrossExecution2", "python", compiledScript), vars); + ExecutableScript script = se.executable(new CompiledScript(ScriptType.INLINE, "testChangingVarsCrossExecution2", "python", compiledScript), vars); script.setNextVar("value", 1); Object o = script.run(); assertThat(((Number) o).intValue(), equalTo(1)); diff --git a/plugins/lang-python/src/test/java/org/elasticsearch/script/python/PythonScriptMultiThreadedTests.java b/plugins/lang-python/src/test/java/org/elasticsearch/script/python/PythonScriptMultiThreadedTests.java index 4bd645ac81a..940a66b43a5 100644 --- a/plugins/lang-python/src/test/java/org/elasticsearch/script/python/PythonScriptMultiThreadedTests.java +++ b/plugins/lang-python/src/test/java/org/elasticsearch/script/python/PythonScriptMultiThreadedTests.java @@ -23,7 +23,7 @@ import org.elasticsearch.common.Randomness; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.script.CompiledScript; import org.elasticsearch.script.ExecutableScript; -import org.elasticsearch.script.ScriptService; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.test.ESTestCase; import java.util.Collections; @@ -40,7 +40,7 @@ public class PythonScriptMultiThreadedTests extends ESTestCase { public void testExecutableNoRuntimeParams() throws Exception { final PythonScriptEngineService se = new PythonScriptEngineService(Settings.Builder.EMPTY_SETTINGS); final Object compiled = se.compile(null, "x + y", Collections.emptyMap()); - final CompiledScript compiledScript = new CompiledScript(ScriptService.ScriptType.INLINE, "testExecutableNoRuntimeParams", "python", compiled); + final CompiledScript compiledScript = new CompiledScript(ScriptType.INLINE, "testExecutableNoRuntimeParams", "python", compiled); final AtomicBoolean failed = new AtomicBoolean(); Thread[] threads = new Thread[4]; @@ -126,7 +126,7 @@ public class PythonScriptMultiThreadedTests extends ESTestCase { public void testExecute() throws Exception { final PythonScriptEngineService se = new PythonScriptEngineService(Settings.Builder.EMPTY_SETTINGS); final Object compiled = se.compile(null, "x + y", Collections.emptyMap()); - final CompiledScript compiledScript = new CompiledScript(ScriptService.ScriptType.INLINE, "testExecute", "python", compiled); + final CompiledScript compiledScript = new CompiledScript(ScriptType.INLINE, "testExecute", "python", compiled); final AtomicBoolean failed = new AtomicBoolean(); Thread[] threads = new Thread[4]; diff --git a/plugins/lang-python/src/test/java/org/elasticsearch/script/python/PythonSecurityTests.java b/plugins/lang-python/src/test/java/org/elasticsearch/script/python/PythonSecurityTests.java index 7ad13b31986..262783dc00c 100644 --- a/plugins/lang-python/src/test/java/org/elasticsearch/script/python/PythonSecurityTests.java +++ b/plugins/lang-python/src/test/java/org/elasticsearch/script/python/PythonSecurityTests.java @@ -21,7 +21,7 @@ package org.elasticsearch.script.python; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.script.CompiledScript; -import org.elasticsearch.script.ScriptService; +import org.elasticsearch.script.ScriptType; import org.elasticsearch.test.ESTestCase; import org.python.core.PyException; @@ -55,7 +55,7 @@ public class PythonSecurityTests extends ESTestCase { /** runs a script */ private void doTest(String script) { Map vars = new HashMap(); - se.executable(new CompiledScript(ScriptService.ScriptType.INLINE, "test", "python", se.compile(null, script, Collections.emptyMap())), vars).run(); + se.executable(new CompiledScript(ScriptType.INLINE, "test", "python", se.compile(null, script, Collections.emptyMap())), vars).run(); } /** asserts that a script runs without exception */ From e745015325b2be7a0c49f6af076040253e302698 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Thu, 27 Oct 2016 09:20:46 +0200 Subject: [PATCH 18/19] Return target index name even if _rollover conditions are not met (#21138) Today we return the old index name as the target / new index name. This change passes the correct rollover index name to the response. --- .../indices/rollover/TransportRolloverAction.java | 2 +- .../test/indices.rollover/10_basic.yaml | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java index de88801825a..d7fd9695e70 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java @@ -149,7 +149,7 @@ public class TransportRolloverAction extends TransportMasterNodeAction Date: Thu, 27 Oct 2016 09:32:01 +0100 Subject: [PATCH 19/19] Correct similarity default for 5.0 (#21144) --- .../mapping/params/similarity.asciidoc | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/docs/reference/mapping/params/similarity.asciidoc b/docs/reference/mapping/params/similarity.asciidoc index 527e961960b..66b1d8a42cf 100644 --- a/docs/reference/mapping/params/similarity.asciidoc +++ b/docs/reference/mapping/params/similarity.asciidoc @@ -15,14 +15,14 @@ similarities. For more details about this expert options, see the The only similarities which can be used out of the box, without any further configuration are: -`classic`:: - The Default TF/IDF algorithm used by Elasticsearch and - Lucene. See {defguide}/practical-scoring-function.html[Lucene’s Practical Scoring Function] +`BM25`:: + The Okapi BM25 algorithm. The algorithm used by default in Elasticsearch and Lucene. + See {defguide}/pluggable-similarites.html[Pluggable Similarity Algorithms] for more information. -`BM25`:: - The Okapi BM25 algorithm. - See {defguide}/pluggable-similarites.html[Pluggable Similarity Algorithms] +`classic`:: + The TF/IDF algorithm which used to be the default in Elasticsearch and + Lucene. See {defguide}/practical-scoring-function.html[Lucene’s Practical Scoring Function] for more information. @@ -39,9 +39,9 @@ PUT my_index "default_field": { <1> "type": "text" }, - "bm25_field": { + "classic_field": { "type": "text", - "similarity": "BM25" <2> + "similarity": "classic" <2> } } } @@ -49,6 +49,5 @@ PUT my_index } -------------------------------------------------- // CONSOLE -<1> The `default_field` uses the `classic` similarity (ie TF/IDF). -<2> The `bm25_field` uses the `BM25` similarity. - +<1> The `default_field` uses the `BM25` similarity. +<2> The `classic_field` uses the `classic` similarity (ie TF/IDF).