From 6bf19fcd930bcfdee25003a62f1c2d1098575eaf Mon Sep 17 00:00:00 2001 From: kimchy Date: Sun, 4 Apr 2010 01:50:52 +0300 Subject: [PATCH] Mapper: Rename allFIeld to _all, sourceField to _source, idField to _id, and typeField to _type, closes #105. --- .../index/mapper/json/JsonAllFieldMapper.java | 2 +- .../index/mapper/json/JsonBoostFieldMapper.java | 2 +- .../index/mapper/json/JsonDocumentMapperParser.java | 12 ++++++------ .../index/mapper/json/JsonIdFieldMapper.java | 6 ++++-- .../index/mapper/json/JsonSourceFieldMapper.java | 2 +- .../index/mapper/json/JsonTypeFieldMapper.java | 6 ++++-- .../index/mapper/json/JsonUidFieldMapper.java | 2 +- .../elasticsearch/index/mapper/json/all/mapping.json | 2 +- .../index/mapper/json/all/store-mapping.json | 2 +- .../mapper/json/simple/test-mapping-notype.json | 8 ++++---- .../index/mapper/json/simple/test-mapping.json | 8 ++++---- .../search/highlight/HighlightSearchTests.java | 2 +- 12 files changed, 29 insertions(+), 25 deletions(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonAllFieldMapper.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonAllFieldMapper.java index 40019f91704..65c9f34e798 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonAllFieldMapper.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonAllFieldMapper.java @@ -42,7 +42,7 @@ import static org.elasticsearch.util.lucene.all.AllTokenFilter.*; */ public class JsonAllFieldMapper extends JsonFieldMapper implements AllFieldMapper { - public static final String JSON_TYPE = "allField"; + public static final String JSON_TYPE = "_all"; public static class Defaults extends JsonFieldMapper.Defaults { public static final String NAME = AllFieldMapper.NAME; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonBoostFieldMapper.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonBoostFieldMapper.java index 965d2bf013a..40e04bc372c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonBoostFieldMapper.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonBoostFieldMapper.java @@ -38,7 +38,7 @@ import java.io.IOException; */ public class JsonBoostFieldMapper extends JsonNumberFieldMapper implements BoostFieldMapper { - public static final String JSON_TYPE = "boostField"; + public static final String JSON_TYPE = "_boost"; public static class Defaults extends JsonNumberFieldMapper.Defaults { public static final String NAME = "_boost"; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonDocumentMapperParser.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonDocumentMapperParser.java index e1ab5f3a643..e723ded8177 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonDocumentMapperParser.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonDocumentMapperParser.java @@ -120,17 +120,17 @@ public class JsonDocumentMapperParser implements DocumentMapperParser { String fieldName = entry.getKey(); JsonNode fieldNode = entry.getValue(); - if (JsonSourceFieldMapper.JSON_TYPE.equals(fieldName)) { + if (JsonSourceFieldMapper.JSON_TYPE.equals(fieldName) || "sourceField".equals(fieldName)) { docBuilder.sourceField(parseSourceField((ObjectNode) fieldNode, parserContext)); - } else if (JsonIdFieldMapper.JSON_TYPE.equals(fieldName)) { + } else if (JsonIdFieldMapper.JSON_TYPE.equals(fieldName) || "idField".equals(fieldName)) { docBuilder.idField(parseIdField((ObjectNode) fieldNode, parserContext)); - } else if (JsonTypeFieldMapper.JSON_TYPE.equals(fieldName)) { + } else if (JsonTypeFieldMapper.JSON_TYPE.equals(fieldName) || "typeField".equals(fieldName)) { docBuilder.typeField(parseTypeField((ObjectNode) fieldNode, parserContext)); - } else if (JsonUidFieldMapper.JSON_TYPE.equals(fieldName)) { + } else if (JsonUidFieldMapper.JSON_TYPE.equals(fieldName) || "uidField".equals(fieldName)) { docBuilder.uidField(parseUidField((ObjectNode) fieldNode, parserContext)); - } else if (JsonBoostFieldMapper.JSON_TYPE.equals(fieldName)) { + } else if (JsonBoostFieldMapper.JSON_TYPE.equals(fieldName) || "boostField".equals(fieldName)) { docBuilder.boostField(parseBoostField((ObjectNode) fieldNode, parserContext)); - } else if (JsonAllFieldMapper.JSON_TYPE.equals(fieldName)) { + } else if (JsonAllFieldMapper.JSON_TYPE.equals(fieldName) || "allField".equals(fieldName)) { docBuilder.allField(parseAllField((ObjectNode) fieldNode, parserContext)); } else if ("indexAnalyzer".equals(fieldName)) { docBuilder.indexAnalyzer(analysisService.analyzer(fieldNode.getTextValue())); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonIdFieldMapper.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonIdFieldMapper.java index 004f729ddd1..971a677f74c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonIdFieldMapper.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonIdFieldMapper.java @@ -35,7 +35,7 @@ import java.io.IOException; */ public class JsonIdFieldMapper extends JsonFieldMapper implements IdFieldMapper { - public static final String JSON_TYPE = "idField"; + public static final String JSON_TYPE = "_id"; public static class Defaults extends JsonFieldMapper.Defaults { public static final String NAME = "_id"; @@ -118,7 +118,9 @@ public class JsonIdFieldMapper extends JsonFieldMapper implements IdFiel } @Override public void toJson(JsonBuilder builder, Params params) throws IOException { - // for now, don't output it at all + builder.startObject(JSON_TYPE); + builder.field("store", store.name().toLowerCase()); + builder.endObject(); } @Override public void merge(JsonMapper mergeWith, JsonMergeContext mergeContext) throws MergeMappingException { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonSourceFieldMapper.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonSourceFieldMapper.java index 9266d81057a..bfc459f6508 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonSourceFieldMapper.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonSourceFieldMapper.java @@ -32,7 +32,7 @@ import java.io.IOException; */ public class JsonSourceFieldMapper extends JsonFieldMapper implements SourceFieldMapper { - public static final String JSON_TYPE = "sourceField"; + public static final String JSON_TYPE = "_source"; public static class Defaults extends JsonFieldMapper.Defaults { public static final String NAME = SourceFieldMapper.NAME; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonTypeFieldMapper.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonTypeFieldMapper.java index c12fde25c9e..1a1d6fb4c05 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonTypeFieldMapper.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonTypeFieldMapper.java @@ -35,7 +35,7 @@ import java.io.IOException; */ public class JsonTypeFieldMapper extends JsonFieldMapper implements TypeFieldMapper { - public static final String JSON_TYPE = "typeField"; + public static final String JSON_TYPE = "_type"; public static class Defaults extends JsonFieldMapper.Defaults { public static final String NAME = TypeFieldMapper.NAME; @@ -107,7 +107,9 @@ public class JsonTypeFieldMapper extends JsonFieldMapper implements Type } @Override public void toJson(JsonBuilder builder, Params params) throws IOException { - // for now, don't output it at all + builder.startObject(JSON_TYPE); + builder.field("store", store.name().toLowerCase()); + builder.endObject(); } @Override public void merge(JsonMapper mergeWith, JsonMergeContext mergeContext) throws MergeMappingException { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonUidFieldMapper.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonUidFieldMapper.java index b6cc0e31258..070610fa516 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonUidFieldMapper.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonUidFieldMapper.java @@ -36,7 +36,7 @@ import java.io.IOException; */ public class JsonUidFieldMapper extends JsonFieldMapper implements UidFieldMapper { - public static final String JSON_TYPE = "uidField"; + public static final String JSON_TYPE = "_uid"; public static class Defaults extends JsonFieldMapper.Defaults { public static final String NAME = UidFieldMapper.NAME; diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/json/all/mapping.json b/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/json/all/mapping.json index 7ba46d2a703..3268d20498d 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/json/all/mapping.json +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/json/all/mapping.json @@ -1,6 +1,6 @@ { person : { - allField : {enabled : true}, + _all : {enabled : true}, properties : { name : { type : "object", diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/json/all/store-mapping.json b/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/json/all/store-mapping.json index 97338ca36b2..beb5eb77544 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/json/all/store-mapping.json +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/json/all/store-mapping.json @@ -1,6 +1,6 @@ { person : { - allField : {enabled : true, store : "yes"}, + _all : {enabled : true, store : "yes"}, properties : { name : { type : "object", diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/json/simple/test-mapping-notype.json b/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/json/simple/test-mapping-notype.json index f5aac46dfcc..c040f44a1e4 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/json/simple/test-mapping-notype.json +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/json/simple/test-mapping-notype.json @@ -2,10 +2,10 @@ dateFormats : ["yyyy-MM-dd", "dd-MM-yyyy"], dynamic : false, enabled : true, - idField : {name : "_id", indexName : "_id"}, - sourceField : {name : "_source", compressionThreshold : 0}, - typeField : {name : "_type"}, - boostField : {name : "_boost", nullValue : 2.0}, + _id : {name : "_id", indexName : "_id"}, + _source : {name : "_source", compressionThreshold : 0}, + _type : {name : "_type"}, + _boost : {name : "_boost", nullValue : 2.0}, properties : { name : { type : "object", diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/json/simple/test-mapping.json b/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/json/simple/test-mapping.json index 8564b1b9bf3..e9cad050215 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/json/simple/test-mapping.json +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/mapper/json/simple/test-mapping.json @@ -3,10 +3,10 @@ dateFormats : ["yyyy-MM-dd", "dd-MM-yyyy"], dynamic : false, enabled : true, - idField : {name : "_id", indexName : "_id"}, - sourceField : {name : "_source", compressionThreshold : 0}, - typeField : {name : "_type"}, - boostField : {name : "_boost", nullValue : 2.0}, + _id : {name : "_id", indexName : "_id"}, + _source : {name : "_source"}, + _type : {name : "_type"}, + _boost : {name : "_boost", nullValue : 2.0}, properties : { name : { type : "object", diff --git a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/highlight/HighlightSearchTests.java b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/highlight/HighlightSearchTests.java index 0b89a6835a1..f0c876b2cbf 100644 --- a/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/highlight/HighlightSearchTests.java +++ b/modules/test/integration/src/test/java/org/elasticsearch/test/integration/search/highlight/HighlightSearchTests.java @@ -109,7 +109,7 @@ public class HighlightSearchTests extends AbstractServersTests { public JsonBuilder mapping() throws IOException { return binaryJsonBuilder().startObject().startObject("type1") - .startObject("allField").field("store", "yes").field("termVector", "with_positions_offsets").endObject() + .startObject("_all").field("store", "yes").field("termVector", "with_positions_offsets").endObject() .endObject().endObject(); }