Skip to content

Commit

Permalink
Mappings: Lock down _type field
Browse files Browse the repository at this point in the history
  • Loading branch information
rjernst committed Feb 25, 2015
1 parent a7f8e63 commit be0cef0
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 11 deletions.
1 change: 1 addition & 0 deletions docs/reference/migration/migrate_2_0.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
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;
Expand Down Expand Up @@ -94,6 +95,9 @@ public TypeFieldMapper build(BuilderContext context) {
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;
Expand Down Expand Up @@ -187,6 +191,9 @@ protected String contentType() {

@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ public void typeFilterTypeNotIndexedTests() throws Exception {
}

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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,6 @@ public void testRootMappersStillWorking() {
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
enabled:true,
_source:{
},
_type:{
},
_boost:{
null_value:2.0
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,8 @@ public void typeFilterTypeNotIndexedTests() throws Exception {
}

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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,6 @@ private XContentBuilder createMapping(String type, String indexAnalyzer, String
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,6 @@ private void randomIndexTemplate() throws IOException {
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())
Expand Down

0 comments on commit be0cef0

Please sign in to comment.