|
24 | 24 | import org.apache.lucene.analysis.standard.StandardAnalyzer;
|
25 | 25 | import org.elasticsearch.Version;
|
26 | 26 | import org.elasticsearch.cluster.metadata.IndexMetaData;
|
| 27 | +import org.elasticsearch.common.bytes.BytesReference; |
27 | 28 | import org.elasticsearch.common.settings.Settings;
|
| 29 | +import org.elasticsearch.common.xcontent.XContentBuilder; |
| 30 | +import org.elasticsearch.common.xcontent.XContentFactory; |
| 31 | +import org.elasticsearch.common.xcontent.XContentHelper; |
28 | 32 | import org.elasticsearch.index.IndexSettings;
|
29 | 33 | import org.elasticsearch.index.analysis.AbstractTokenFilterFactory;
|
30 | 34 | import org.elasticsearch.index.analysis.AnalysisMode;
|
|
36 | 40 | import org.elasticsearch.index.analysis.TokenFilterFactory;
|
37 | 41 | import org.elasticsearch.test.ESTestCase;
|
38 | 42 |
|
| 43 | +import java.io.IOException; |
39 | 44 | import java.util.Collections;
|
40 | 45 | import java.util.HashMap;
|
41 | 46 | import java.util.Map;
|
@@ -157,6 +162,38 @@ public void testParseTextFieldCheckAnalyzerWithSearchAnalyzerAnalysisMode() {
|
157 | 162 | TypeParsers.parseTextField(builder, "name", new HashMap<>(fieldNode), parserContext);
|
158 | 163 | }
|
159 | 164 |
|
| 165 | + public void testMultiFieldWithinMultiField() throws IOException { |
| 166 | + TextFieldMapper.Builder builder = new TextFieldMapper.Builder("textField"); |
| 167 | + |
| 168 | + XContentBuilder mapping = XContentFactory.jsonBuilder().startObject() |
| 169 | + .field("type", "keyword") |
| 170 | + .startObject("fields") |
| 171 | + .startObject("sub-field") |
| 172 | + .field("type", "keyword") |
| 173 | + .startObject("fields") |
| 174 | + .startObject("sub-sub-field") |
| 175 | + .field("type", "keyword") |
| 176 | + .endObject() |
| 177 | + .endObject() |
| 178 | + .endObject() |
| 179 | + .endObject() |
| 180 | + .endObject(); |
| 181 | + |
| 182 | + Map<String, Object> fieldNode = XContentHelper.convertToMap( |
| 183 | + BytesReference.bytes(mapping), true, mapping.contentType()).v2(); |
| 184 | + |
| 185 | + Mapper.TypeParser typeParser = new KeywordFieldMapper.TypeParser(); |
| 186 | + Mapper.TypeParser.ParserContext parserContext = new Mapper.TypeParser.ParserContext("type", |
| 187 | + null, null, type -> typeParser, Version.CURRENT, null); |
| 188 | + |
| 189 | + TypeParsers.parseField(builder, "some-field", fieldNode, parserContext); |
| 190 | + assertWarnings("At least one multi-field, [sub-field], was " + |
| 191 | + "encountered that itself contains a multi-field. Defining multi-fields within a multi-field is deprecated and will " + |
| 192 | + "no longer be supported in 8.0. To resolve the issue, all instances of [fields] that occur within a [fields] block " + |
| 193 | + "should be removed from the mappings, either by flattening the chained [fields] blocks into a single level, or " + |
| 194 | + "switching to [copy_to] if appropriate."); |
| 195 | + } |
| 196 | + |
160 | 197 | private Analyzer createAnalyzerWithMode(String name, AnalysisMode mode) {
|
161 | 198 | TokenFilterFactory tokenFilter = new AbstractTokenFilterFactory(indexSettings, name, Settings.EMPTY) {
|
162 | 199 | @Override
|
|
0 commit comments