From f3cc8d12496f3a18af839f561db8a8f9b79167dd Mon Sep 17 00:00:00 2001 From: kimchy Date: Mon, 9 Aug 2010 18:25:45 +0300 Subject: [PATCH] when serializing mappers into json, also serialize index, type and id mappings (index for the enabled flag, and id/type for the store) --- .../index/mapper/xcontent/XContentDocumentMapper.java | 8 +++++++- .../index/mapper/xcontent/index/IndexTypeMapperTests.java | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/XContentDocumentMapper.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/XContentDocumentMapper.java index ad0c6bab3ae..69b3dec91bc 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/XContentDocumentMapper.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/XContentDocumentMapper.java @@ -228,6 +228,9 @@ public class XContentDocumentMapper implements DocumentMapper, ToXContent { final List tempFieldMappers = newArrayList(); // add the basic ones + if (indexFieldMapper.enabled()) { + tempFieldMappers.add(indexFieldMapper); + } tempFieldMappers.add(typeFieldMapper); tempFieldMappers.add(sourceFieldMapper); tempFieldMappers.add(uidFieldMapper); @@ -391,6 +394,9 @@ public class XContentDocumentMapper implements DocumentMapper, ToXContent { synchronized (mutex) { fieldMapperListeners.add(fieldMapperListener); if (includeExisting) { + if (indexFieldMapper.enabled()) { + fieldMapperListener.fieldMapper(indexFieldMapper); + } fieldMapperListener.fieldMapper(sourceFieldMapper); fieldMapperListener.fieldMapper(typeFieldMapper); fieldMapperListener.fieldMapper(idFieldMapper); @@ -427,6 +433,6 @@ public class XContentDocumentMapper implements DocumentMapper, ToXContent { } @Override public void toXContent(XContentBuilder builder, Params params) throws IOException { - rootObjectMapper.toXContent(builder, params, allFieldMapper, sourceFieldMapper); + rootObjectMapper.toXContent(builder, params, indexFieldMapper, typeFieldMapper, idFieldMapper, allFieldMapper, sourceFieldMapper); } } diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/xcontent/index/IndexTypeMapperTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/xcontent/index/IndexTypeMapperTests.java index 4f32d32a59c..cf3ef8994b0 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/xcontent/index/IndexTypeMapperTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/xcontent/index/IndexTypeMapperTests.java @@ -22,6 +22,7 @@ package org.elasticsearch.index.mapper.xcontent.index; import org.apache.lucene.document.Field; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.index.mapper.IndexFieldMapper; import org.elasticsearch.index.mapper.ParsedDocument; import org.elasticsearch.index.mapper.xcontent.XContentDocumentMapper; import org.elasticsearch.index.mapper.xcontent.XContentMapperTests; @@ -42,6 +43,7 @@ public class IndexTypeMapperTests { XContentDocumentMapper docMapper = XContentMapperTests.newParser().parse(mapping); assertThat(docMapper.indexMapper().enabled(), equalTo(true)); assertThat(docMapper.indexMapper().store(), equalTo(Field.Store.YES)); + assertThat(docMapper.mappers().indexName("_index").mapper(), instanceOf(IndexFieldMapper.class)); ParsedDocument doc = docMapper.parse("type", "1", XContentFactory.jsonBuilder() .startObject()