Skip to content

Commit 661117c

Browse files
kelcbuescher
kel
authored andcommitted
Replace delimited_payload_filter by delimited_payload (#26625)
The `delimited_payload_filter` is renamed to `delimited_payload`, the old name is deprecated and should be replaced by `delimited_payload`. Closes #21978
1 parent 89c2ed8 commit 661117c

File tree

7 files changed

+96
-6
lines changed

7 files changed

+96
-6
lines changed

core/src/main/java/org/elasticsearch/index/analysis/AnalysisRegistry.java

+1
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ public String toString() {
305305
};
306306
}
307307

308+
@SuppressWarnings("unchecked")
308309
private <T> Map<String, T> buildMapping(Component component, IndexSettings settings, Map<String, Settings> settingsMap,
309310
Map<String, ? extends AnalysisModule.AnalysisProvider<T>> providerMap,
310311
Map<String, ? extends AnalysisModule.AnalysisProvider<T>> defaultInstance) throws IOException {

core/src/test/java/org/elasticsearch/action/termvectors/GetTermVectorsTests.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,10 @@ public void testRandomPayloadWithDelimitedPayloadTokenFilter() throws IOExceptio
152152
.field("analyzer", "payload_test").endObject().endObject().endObject().endObject();
153153
Settings setting = Settings.builder()
154154
.put("index.analysis.analyzer.payload_test.tokenizer", "whitespace")
155-
.putList("index.analysis.analyzer.payload_test.filter", "my_delimited_payload_filter")
156-
.put("index.analysis.filter.my_delimited_payload_filter.delimiter", delimiter)
157-
.put("index.analysis.filter.my_delimited_payload_filter.encoding", encodingString)
158-
.put("index.analysis.filter.my_delimited_payload_filter.type", "mock_payload_filter").build();
155+
.putList("index.analysis.analyzer.payload_test.filter", "my_delimited_payload")
156+
.put("index.analysis.filter.my_delimited_payload.delimiter", delimiter)
157+
.put("index.analysis.filter.my_delimited_payload.encoding", encodingString)
158+
.put("index.analysis.filter.my_delimited_payload.type", "mock_payload_filter").build();
159159
createIndex("test", setting, "type1", mapping);
160160

161161
client().prepareIndex("test", "type1", Integer.toString(1))

docs/reference/analysis/tokenfilters/delimited-payload-tokenfilter.asciidoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[[analysis-delimited-payload-tokenfilter]]
22
=== Delimited Payload Token Filter
33

4-
Named `delimited_payload_filter`. Splits tokens into tokens and payload whenever a delimiter character is found.
4+
Named `delimited_payload`. Splits tokens into tokens and payload whenever a delimiter character is found.
55

66
Example: "the|1 quick|2 fox|3" is split by default into tokens `the`, `quick`, and `fox` with payloads `1`, `2`, and `3` respectively.
77

modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/CommonAnalysisPlugin.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ public Map<String, AnalysisProvider<TokenFilterFactory>> getTokenFilters() {
103103
filters.put("czech_stem", CzechStemTokenFilterFactory::new);
104104
filters.put("common_grams", requriesAnalysisSettings(CommonGramsTokenFilterFactory::new));
105105
filters.put("decimal_digit", DecimalDigitFilterFactory::new);
106-
filters.put("delimited_payload_filter", DelimitedPayloadTokenFilterFactory::new);
106+
filters.put("delimited_payload_filter", LegacyDelimitedPayloadTokenFilterFactory::new);
107+
filters.put("delimited_payload", DelimitedPayloadTokenFilterFactory::new);
107108
filters.put("dictionary_decompounder", requriesAnalysisSettings(DictionaryCompoundWordTokenFilterFactory::new));
108109
filters.put("dutch_stem", DutchStemTokenFilterFactory::new);
109110
filters.put("edge_ngram", EdgeNGramTokenFilterFactory::new);
@@ -195,6 +196,10 @@ public List<PreConfiguredTokenFilter> getPreConfiguredTokenFilters() {
195196
new DelimitedPayloadTokenFilter(input,
196197
DelimitedPayloadTokenFilterFactory.DEFAULT_DELIMITER,
197198
DelimitedPayloadTokenFilterFactory.DEFAULT_ENCODER)));
199+
filters.add(PreConfiguredTokenFilter.singleton("delimited_payload", false, input ->
200+
new DelimitedPayloadTokenFilter(input,
201+
DelimitedPayloadTokenFilterFactory.DEFAULT_DELIMITER,
202+
DelimitedPayloadTokenFilterFactory.DEFAULT_ENCODER)));
198203
filters.add(PreConfiguredTokenFilter.singleton("dutch_stem", false, input -> new SnowballFilter(input, new DutchStemmer())));
199204
filters.add(PreConfiguredTokenFilter.singleton("edge_ngram", false, input ->
200205
new EdgeNGramTokenFilter(input, EdgeNGramTokenFilter.DEFAULT_MIN_GRAM_SIZE, EdgeNGramTokenFilter.DEFAULT_MAX_GRAM_SIZE)));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.analysis.common;
21+
22+
import org.elasticsearch.Version;
23+
import org.elasticsearch.common.logging.DeprecationLogger;
24+
import org.elasticsearch.common.logging.Loggers;
25+
import org.elasticsearch.common.settings.Settings;
26+
import org.elasticsearch.env.Environment;
27+
import org.elasticsearch.index.IndexSettings;
28+
29+
public class LegacyDelimitedPayloadTokenFilterFactory extends DelimitedPayloadTokenFilterFactory {
30+
private static final DeprecationLogger DEPRECATION_LOGGER =
31+
new DeprecationLogger(Loggers.getLogger(LegacyDelimitedPayloadTokenFilterFactory.class));
32+
33+
LegacyDelimitedPayloadTokenFilterFactory(IndexSettings indexSettings, Environment env, String name, Settings settings) {
34+
super(indexSettings, env, name, settings);
35+
if (indexSettings.getIndexVersionCreated().onOrAfter(Version.V_7_0_0_alpha1)) {
36+
DEPRECATION_LOGGER.deprecated("Deprecated [delimited_payload_filter] used, replaced by [delimited_payload]");
37+
}
38+
}
39+
}

modules/analysis-common/src/test/java/org/elasticsearch/analysis/common/CommonAnalysisFactoryTests.java

+1
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ protected Map<String, Class<?>> getPreConfiguredTokenFilters() {
170170
filters.put("czech_stem", null);
171171
filters.put("decimal_digit", null);
172172
filters.put("delimited_payload_filter", org.apache.lucene.analysis.payloads.DelimitedPayloadTokenFilterFactory.class);
173+
filters.put("delimited_payload", org.apache.lucene.analysis.payloads.DelimitedPayloadTokenFilterFactory.class);
173174
filters.put("dutch_stem", SnowballPorterFilterFactory.class);
174175
filters.put("edge_ngram", null);
175176
filters.put("edgeNGram", null);

modules/analysis-common/src/test/resources/rest-api-spec/test/analysis-common/40_token_filters.yml

+44
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,14 @@
10271027

10281028
---
10291029
"delimited_payload_filter":
1030+
- skip:
1031+
version: " - 6.99.99"
1032+
reason: delimited_payload_filter deprecated in 7.0, replaced by delimited_payload
1033+
features: "warnings"
1034+
10301035
- do:
1036+
warnings:
1037+
- "Deprecated [delimited_payload_filter] used, replaced by [delimited_payload]"
10311038
indices.create:
10321039
index: test
10331040
body:
@@ -1039,6 +1046,8 @@
10391046
delimiter: ^
10401047
encoding: identity
10411048
- do:
1049+
warnings:
1050+
- "Deprecated [delimited_payload_filter] used, replaced by [delimited_payload]"
10421051
indices.analyze:
10431052
index: test
10441053
body:
@@ -1050,6 +1059,8 @@
10501059

10511060
# Test pre-configured token filter too:
10521061
- do:
1062+
warnings:
1063+
- "Deprecated [delimited_payload_filter] used, replaced by [delimited_payload]"
10531064
indices.analyze:
10541065
body:
10551066
text: foo|5
@@ -1058,6 +1069,39 @@
10581069
- length: { tokens: 1 }
10591070
- match: { tokens.0.token: foo }
10601071

1072+
---
1073+
"delimited_payload":
1074+
- do:
1075+
indices.create:
1076+
index: test
1077+
body:
1078+
settings:
1079+
analysis:
1080+
filter:
1081+
my_delimited_payload:
1082+
type: delimited_payload
1083+
delimiter: ^
1084+
encoding: identity
1085+
- do:
1086+
indices.analyze:
1087+
index: test
1088+
body:
1089+
text: foo^bar
1090+
tokenizer: keyword
1091+
filter: [my_delimited_payload]
1092+
- length: { tokens: 1 }
1093+
- match: { tokens.0.token: foo }
1094+
1095+
# Test pre-configured token filter too:
1096+
- do:
1097+
indices.analyze:
1098+
body:
1099+
text: foo|5
1100+
tokenizer: keyword
1101+
filter: [delimited_payload]
1102+
- length: { tokens: 1 }
1103+
- match: { tokens.0.token: foo }
1104+
10611105
---
10621106
"keep_filter":
10631107
- do:

0 commit comments

Comments
 (0)