|
@@ -28,7 +28,10 @@ import org.apache.lucene.index.PostingsEnum;
|
|
|
import org.apache.lucene.index.Term;
|
|
|
import org.apache.lucene.index.TermsEnum;
|
|
|
import org.apache.lucene.util.BytesRef;
|
|
|
+import org.elasticsearch.Version;
|
|
|
+import org.elasticsearch.cluster.metadata.IndexMetaData;
|
|
|
import org.elasticsearch.common.compress.CompressedXContent;
|
|
|
+import org.elasticsearch.common.settings.Settings;
|
|
|
import org.elasticsearch.common.xcontent.ToXContent;
|
|
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
|
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
|
@@ -36,21 +39,27 @@ import org.elasticsearch.index.IndexService;
|
|
|
import org.elasticsearch.index.engine.Engine;
|
|
|
import org.elasticsearch.index.mapper.DocumentMapper;
|
|
|
import org.elasticsearch.index.mapper.DocumentMapperParser;
|
|
|
+import org.elasticsearch.index.mapper.FieldMapper;
|
|
|
import org.elasticsearch.index.mapper.MapperParsingException;
|
|
|
import org.elasticsearch.index.mapper.MapperService.MergeReason;
|
|
|
import org.elasticsearch.index.mapper.TextFieldMapper.TextFieldType;
|
|
|
import org.elasticsearch.index.mapper.ParsedDocument;
|
|
|
import org.elasticsearch.index.mapper.TextFieldMapper;
|
|
|
import org.elasticsearch.index.shard.IndexShard;
|
|
|
+import org.elasticsearch.plugins.Plugin;
|
|
|
import org.elasticsearch.test.ESSingleNodeTestCase;
|
|
|
+import org.elasticsearch.test.InternalSettingsPlugin;
|
|
|
+import org.elasticsearch.test.VersionUtils;
|
|
|
import org.junit.Before;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
+import java.util.Collection;
|
|
|
import java.util.Collections;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
|
|
|
+import static com.carrotsearch.randomizedtesting.RandomizedTest.getRandom;
|
|
|
import static org.hamcrest.Matchers.containsString;
|
|
|
import static org.hamcrest.Matchers.equalTo;
|
|
|
|
|
@@ -65,6 +74,11 @@ public class TextFieldMapperTests extends ESSingleNodeTestCase {
|
|
|
parser = indexService.mapperService().documentMapperParser();
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ protected Collection<Class<? extends Plugin>> getPlugins() {
|
|
|
+ return pluginList(InternalSettingsPlugin.class);
|
|
|
+ }
|
|
|
+
|
|
|
public void testDefaults() throws Exception {
|
|
|
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
.startObject("properties").startObject("field").field("type", "text").endObject().endObject()
|
|
@@ -549,4 +563,25 @@ public class TextFieldMapperTests extends ESSingleNodeTestCase {
|
|
|
assertEquals("Cannot set position_increment_gap on field [field] without positions enabled", e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public void testEmptyName() throws IOException {
|
|
|
+ // after 5.x
|
|
|
+ String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
|
|
|
+ .startObject("properties").startObject("").field("type", "text").endObject().endObject()
|
|
|
+ .endObject().endObject().string();
|
|
|
+
|
|
|
+ IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
|
|
|
+ () -> parser.parse("type", new CompressedXContent(mapping))
|
|
|
+ );
|
|
|
+ assertThat(e.getMessage(), containsString("name cannot be empty string"));
|
|
|
+
|
|
|
+ // before 5.x
|
|
|
+ Version oldVersion = VersionUtils.randomVersionBetween(getRandom(), Version.V_2_0_0, Version.V_2_3_5);
|
|
|
+ Settings oldIndexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, oldVersion).build();
|
|
|
+ indexService = createIndex("test_old", oldIndexSettings);
|
|
|
+ parser = indexService.mapperService().documentMapperParser();
|
|
|
+
|
|
|
+ DocumentMapper defaultMapper = parser.parse("type", new CompressedXContent(mapping));
|
|
|
+ assertEquals(mapping, defaultMapper.mappingSource().string());
|
|
|
+ }
|
|
|
}
|