Mappings: Lock down _type field

see 
closes 
This commit is contained in:
Ryan Ernst 2015-02-24 15:56:46 -08:00
parent a7f8e636ba
commit be0cef0c43
8 changed files with 12 additions and 11 deletions
docs/reference/migration
src
main/java/org/elasticsearch/index/mapper/internal
test/java/org/elasticsearch

@ -242,6 +242,7 @@ Meta fields (those beginning with underscore) are fields used by elasticsearch
to provide special features. They now have limited configuration options.
* `_id` configuration can no longer be changed. If you need to sort, use `_uid` instead.
* `_type` configuration can no longer be changed.
=== Codecs

@ -30,6 +30,7 @@ import org.apache.lucene.search.Filter;
import org.apache.lucene.search.PrefixFilter;
import org.apache.lucene.search.Query;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.Version;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.lucene.BytesRefs;
import org.elasticsearch.common.lucene.Lucene;
@ -94,6 +95,9 @@ public class TypeFieldMapper extends AbstractFieldMapper<String> implements Inte
public static class TypeParser implements Mapper.TypeParser {
@Override
public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
if (parserContext.indexVersionCreated().onOrAfter(Version.V_2_0_0)) {
throw new MapperParsingException(NAME + " is not configurable");
}
TypeFieldMapper.Builder builder = type();
parseField(builder, builder.name, node, parserContext);
return builder;
@ -187,6 +191,9 @@ public class TypeFieldMapper extends AbstractFieldMapper<String> implements Inte
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
if (writePre2xSettings == false) {
return builder;
}
boolean includeDefaults = params.paramAsBoolean("include_defaults", false);
// if all are defaults, no sense to write it at all

@ -227,7 +227,8 @@ public class CountQueryTests extends ElasticsearchIntegrationTest {
}
private void typeFilterTests(String index) throws Exception {
assertAcked(prepareCreate("test")
Settings indexSettings = ImmutableSettings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_1_4_2.id).build();
assertAcked(prepareCreate("test").setSettings(indexSettings)
.addMapping("type1", jsonBuilder().startObject().startObject("type1")
.startObject("_type").field("index", index).endObject()
.endObject().endObject())

@ -417,7 +417,6 @@ public class SimpleAllMapperTests extends ElasticsearchSingleNodeTest {
rootTypes.put(SizeFieldMapper.NAME, "{\"enabled\" : true}");
rootTypes.put(IndexFieldMapper.NAME, "{\"enabled\" : true}");
rootTypes.put(SourceFieldMapper.NAME, "{\"enabled\" : true}");
rootTypes.put(TypeFieldMapper.NAME, "{\"store\" : true}");
rootTypes.put("include_in_all", "true");
rootTypes.put("dynamic_date_formats", "[\"yyyy-MM-dd\", \"dd-MM-yyyy\"]");
rootTypes.put("numeric_detection", "true");

@ -8,8 +8,6 @@
enabled:true,
_source:{
},
_type:{
},
_boost:{
null_value:2.0
},

@ -597,7 +597,8 @@ public class SearchQueryTests extends ElasticsearchIntegrationTest {
}
private void typeFilterTests(String index) throws Exception {
assertAcked(prepareCreate("test")
Settings indexSettings = ImmutableSettings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_1_4_2.id).build();
assertAcked(prepareCreate("test").setSettings(indexSettings)
.addMapping("type1", jsonBuilder().startObject().startObject("type1")
.startObject("_type").field("index", index).endObject()
.endObject().endObject())

@ -967,7 +967,6 @@ public class ContextSuggestSearchTests extends ElasticsearchIntegrationTest {
XContentBuilder mapping = jsonBuilder();
mapping.startObject();
mapping.startObject(type);
mapping.startObject("_type").field("index", "not_analyzed").endObject(); // Forcefully configure the _type field, since it can be randomized and if used as context it needs to be enabled
mapping.startObject("properties");
mapping.startObject(FIELD);
mapping.field("type", "completion");

@ -312,11 +312,6 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase
XContentBuilder mappings = null;
if (frequently() && randomDynamicTemplates()) {
mappings = XContentFactory.jsonBuilder().startObject().startObject("_default_");
if (randomBoolean()) {
mappings.startObject(TypeFieldMapper.NAME)
.field("index", randomFrom("no", "not_analyzed"))
.endObject();
}
if (randomBoolean()) {
mappings.startObject(TimestampFieldMapper.NAME)
.field("enabled", randomBoolean())