diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonBooleanFieldMapper.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonBooleanFieldMapper.java index 0528f830e52..9be1a3ef8da 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonBooleanFieldMapper.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonBooleanFieldMapper.java @@ -26,6 +26,7 @@ import org.codehaus.jackson.JsonToken; import org.codehaus.jackson.node.ObjectNode; import org.elasticsearch.index.mapper.MapperParsingException; import org.elasticsearch.util.Booleans; +import org.elasticsearch.util.Strings; import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.lucene.Lucene; @@ -102,9 +103,9 @@ public class JsonBooleanFieldMapper extends JsonFieldMapper { parseJsonField(builder, name, booleanNode, parserContext); for (Iterator> propsIt = booleanNode.getFields(); propsIt.hasNext();) { Map.Entry entry = propsIt.next(); - String propName = entry.getKey(); + String propName = Strings.toUnderscoreCase(entry.getKey()); JsonNode propNode = entry.getValue(); - if (propName.equals("nullValue") || propName.equals("null_value")) { + if (propName.equals("null_value")) { builder.nullValue(nodeBooleanValue(propNode)); } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonDateFieldMapper.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonDateFieldMapper.java index aefb57d3349..250e63a8123 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonDateFieldMapper.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonDateFieldMapper.java @@ -30,6 +30,7 @@ import org.elasticsearch.index.analysis.NamedAnalyzer; import org.elasticsearch.index.analysis.NumericDateAnalyzer; import org.elasticsearch.index.mapper.MapperParsingException; import org.elasticsearch.util.Numbers; +import org.elasticsearch.util.Strings; import org.elasticsearch.util.joda.FormatDateTimeFormatter; import org.elasticsearch.util.joda.Joda; import org.elasticsearch.util.json.JsonBuilder; @@ -90,9 +91,9 @@ public class JsonDateFieldMapper extends JsonNumberFieldMapper { parseNumberField(builder, name, dateNode, parserContext); for (Iterator> propsIt = dateNode.getFields(); propsIt.hasNext();) { Map.Entry entry = propsIt.next(); - String propName = entry.getKey(); + String propName = Strings.toUnderscoreCase(entry.getKey()); JsonNode propNode = entry.getValue(); - if (propName.equals("nullValue") || propName.equals("null_value")) { + if (propName.equals("null_value")) { builder.nullValue(propNode.getValueAsText()); } else if (propName.equals("format")) { builder.dateTimeFormatter(parseDateTimeFormatter(propName, propNode)); 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 3086175ccf1..dd815e842c6 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 @@ -28,6 +28,7 @@ import org.elasticsearch.index.mapper.DocumentMapper; import org.elasticsearch.index.mapper.DocumentMapperParser; import org.elasticsearch.index.mapper.MapperParsingException; import org.elasticsearch.util.MapBuilder; +import org.elasticsearch.util.Strings; import org.elasticsearch.util.io.FastStringReader; import org.elasticsearch.util.json.Jackson; @@ -117,7 +118,7 @@ public class JsonDocumentMapperParser implements DocumentMapperParser { for (Iterator> fieldsIt = rootObj.getFields(); fieldsIt.hasNext();) { Map.Entry entry = fieldsIt.next(); - String fieldName = entry.getKey(); + String fieldName = Strings.toUnderscoreCase(entry.getKey()); JsonNode fieldNode = entry.getValue(); if (JsonSourceFieldMapper.JSON_TYPE.equals(fieldName) || "sourceField".equals(fieldName)) { @@ -178,7 +179,7 @@ public class JsonDocumentMapperParser implements DocumentMapperParser { parseNumberField(builder, name, boostNode, parserContext); for (Iterator> propsIt = boostNode.getFields(); propsIt.hasNext();) { Map.Entry entry = propsIt.next(); - String propName = entry.getKey(); + String propName = Strings.toUnderscoreCase(entry.getKey()); JsonNode propNode = entry.getValue(); if (propName.equals("null_value")) { builder.nullValue(nodeFloatValue(propNode)); @@ -208,7 +209,7 @@ public class JsonDocumentMapperParser implements DocumentMapperParser { parseJsonField(builder, builder.name, allNode, parserContext); for (Iterator> fieldsIt = allNode.getFields(); fieldsIt.hasNext();) { Map.Entry entry = fieldsIt.next(); - String fieldName = entry.getKey(); + String fieldName = Strings.toUnderscoreCase(entry.getKey()); JsonNode fieldNode = entry.getValue(); if (fieldName.equals("enabled")) { builder.enabled(nodeBooleanValue(fieldNode)); @@ -222,7 +223,7 @@ public class JsonDocumentMapperParser implements DocumentMapperParser { JsonSourceFieldMapper.Builder builder = source(); for (Iterator> fieldsIt = sourceNode.getFields(); fieldsIt.hasNext();) { Map.Entry entry = fieldsIt.next(); - String fieldName = entry.getKey(); + String fieldName = Strings.toUnderscoreCase(entry.getKey()); JsonNode fieldNode = entry.getValue(); if (fieldName.equals("enabled")) { builder.enabled(nodeBooleanValue(fieldNode)); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonFloatFieldMapper.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonFloatFieldMapper.java index 67ae4efa713..fa6810c23d1 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonFloatFieldMapper.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonFloatFieldMapper.java @@ -30,6 +30,7 @@ import org.elasticsearch.index.analysis.NamedAnalyzer; import org.elasticsearch.index.analysis.NumericFloatAnalyzer; import org.elasticsearch.index.mapper.MapperParsingException; import org.elasticsearch.util.Numbers; +import org.elasticsearch.util.Strings; import org.elasticsearch.util.json.JsonBuilder; import java.io.IOException; @@ -80,9 +81,9 @@ public class JsonFloatFieldMapper extends JsonNumberFieldMapper { parseNumberField(builder, name, floatNode, parserContext); for (Iterator> propsIt = floatNode.getFields(); propsIt.hasNext();) { Map.Entry entry = propsIt.next(); - String propName = entry.getKey(); + String propName = Strings.toUnderscoreCase(entry.getKey()); JsonNode propNode = entry.getValue(); - if (propName.equals("nullValue") || propName.equals("null_value")) { + if (propName.equals("null_value")) { builder.nullValue(nodeFloatValue(propNode)); } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonIntegerFieldMapper.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonIntegerFieldMapper.java index b874b446a51..9f8d9b1e697 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonIntegerFieldMapper.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonIntegerFieldMapper.java @@ -30,6 +30,7 @@ import org.elasticsearch.index.analysis.NamedAnalyzer; import org.elasticsearch.index.analysis.NumericIntegerAnalyzer; import org.elasticsearch.index.mapper.MapperParsingException; import org.elasticsearch.util.Numbers; +import org.elasticsearch.util.Strings; import org.elasticsearch.util.json.JsonBuilder; import java.io.IOException; @@ -80,9 +81,9 @@ public class JsonIntegerFieldMapper extends JsonNumberFieldMapper { parseNumberField(builder, name, integerNode, parserContext); for (Iterator> propsIt = integerNode.getFields(); propsIt.hasNext();) { Map.Entry entry = propsIt.next(); - String propName = entry.getKey(); + String propName = Strings.toUnderscoreCase(entry.getKey()); JsonNode propNode = entry.getValue(); - if (propName.equals("nullValue")) { + if (propName.equals("null_value")) { builder.nullValue(nodeIntegerValue(propNode)); } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonLongFieldMapper.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonLongFieldMapper.java index abb894880b7..35a003f0533 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonLongFieldMapper.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonLongFieldMapper.java @@ -30,6 +30,7 @@ import org.elasticsearch.index.analysis.NamedAnalyzer; import org.elasticsearch.index.analysis.NumericLongAnalyzer; import org.elasticsearch.index.mapper.MapperParsingException; import org.elasticsearch.util.Numbers; +import org.elasticsearch.util.Strings; import org.elasticsearch.util.json.JsonBuilder; import java.io.IOException; @@ -80,9 +81,9 @@ public class JsonLongFieldMapper extends JsonNumberFieldMapper { parseNumberField(builder, name, longNode, parserContext); for (Iterator> propsIt = longNode.getFields(); propsIt.hasNext();) { Map.Entry entry = propsIt.next(); - String propName = entry.getKey(); + String propName = Strings.toUnderscoreCase(entry.getKey()); JsonNode propNode = entry.getValue(); - if (propName.equals("nullValue")) { + if (propName.equals("null_value")) { builder.nullValue(nodeLongValue(propNode)); } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonMultiFieldMapper.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonMultiFieldMapper.java index c37567ea032..ca55a801afb 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonMultiFieldMapper.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonMultiFieldMapper.java @@ -26,6 +26,7 @@ import org.elasticsearch.index.mapper.FieldMapper; import org.elasticsearch.index.mapper.FieldMapperListener; import org.elasticsearch.index.mapper.MapperParsingException; import org.elasticsearch.index.mapper.MergeMappingException; +import org.elasticsearch.util.Strings; import org.elasticsearch.util.json.JsonBuilder; import java.io.IOException; @@ -106,7 +107,7 @@ public class JsonMultiFieldMapper implements JsonMapper, JsonIncludeInAllMapper JsonMultiFieldMapper.Builder builder = multiField(name); for (Iterator> fieldsIt = multiFieldNode.getFields(); fieldsIt.hasNext();) { Map.Entry entry = fieldsIt.next(); - String fieldName = entry.getKey(); + String fieldName = Strings.toUnderscoreCase(entry.getKey()); JsonNode fieldNode = entry.getValue(); if (fieldName.equals("path")) { builder.pathType(parsePathType(name, fieldNode.getValueAsText())); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonObjectMapper.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonObjectMapper.java index 9766aa945c4..ee371dbda91 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonObjectMapper.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonObjectMapper.java @@ -27,6 +27,7 @@ import org.codehaus.jackson.node.ArrayNode; import org.codehaus.jackson.node.ObjectNode; import org.elasticsearch.ElasticSearchIllegalStateException; import org.elasticsearch.index.mapper.*; +import org.elasticsearch.util.Strings; import org.elasticsearch.util.concurrent.ThreadSafe; import org.elasticsearch.util.joda.FormatDateTimeFormatter; import org.elasticsearch.util.json.JsonBuilder; @@ -160,7 +161,7 @@ public class JsonObjectMapper implements JsonMapper, JsonIncludeInAllMapper { JsonObjectMapper.Builder builder = object(name); for (Iterator> fieldsIt = objectNode.getFields(); fieldsIt.hasNext();) { Map.Entry entry = fieldsIt.next(); - String fieldName = entry.getKey(); + String fieldName = Strings.toUnderscoreCase(entry.getKey()); JsonNode fieldNode = entry.getValue(); if (fieldName.equals("dynamic")) { builder.dynamic(nodeBooleanValue(fieldNode)); @@ -169,7 +170,7 @@ public class JsonObjectMapper implements JsonMapper, JsonIncludeInAllMapper { if (!type.equals("object")) { throw new MapperParsingException("Trying to parse an object but has a different type [" + type + "] for [" + name + "]"); } - } else if (fieldName.equals("dateFormats") || fieldName.equals("date_formats")) { + } else if (fieldName.equals("date_formats")) { List dateTimeFormatters = newArrayList(); if (fieldNode.isArray()) { for (JsonNode node1 : (ArrayNode) fieldNode) { @@ -191,7 +192,7 @@ public class JsonObjectMapper implements JsonMapper, JsonIncludeInAllMapper { builder.pathType(parsePathType(name, fieldNode.getValueAsText())); } else if (fieldName.equals("properties")) { parseProperties(builder, (ObjectNode) fieldNode, parserContext); - } else if (fieldName.equals("includeInAll") || fieldName.equals("include_in_all")) { + } else if (fieldName.equals("include_in_all")) { builder.includeInAll(nodeBooleanValue(fieldNode)); } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonShortFieldMapper.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonShortFieldMapper.java index 16f4e2639f2..65739457557 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonShortFieldMapper.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonShortFieldMapper.java @@ -30,6 +30,7 @@ import org.elasticsearch.index.analysis.NamedAnalyzer; import org.elasticsearch.index.analysis.NumericIntegerAnalyzer; import org.elasticsearch.index.mapper.MapperParsingException; import org.elasticsearch.util.Numbers; +import org.elasticsearch.util.Strings; import org.elasticsearch.util.json.JsonBuilder; import java.io.IOException; @@ -80,9 +81,9 @@ public class JsonShortFieldMapper extends JsonNumberFieldMapper { parseNumberField(builder, name, shortNode, parserContext); for (Iterator> propsIt = shortNode.getFields(); propsIt.hasNext();) { Map.Entry entry = propsIt.next(); - String propName = entry.getKey(); + String propName = Strings.toUnderscoreCase(entry.getKey()); JsonNode propNode = entry.getValue(); - if (propName.equals("nullValue") || propName.equals("null_value")) { + if (propName.equals("null_value")) { builder.nullValue(nodeShortValue(propNode)); } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonStringFieldMapper.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonStringFieldMapper.java index 472e420a37e..22f3323e495 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonStringFieldMapper.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonStringFieldMapper.java @@ -26,6 +26,7 @@ import org.codehaus.jackson.JsonToken; import org.codehaus.jackson.node.ObjectNode; import org.elasticsearch.index.analysis.NamedAnalyzer; import org.elasticsearch.index.mapper.MapperParsingException; +import org.elasticsearch.util.Strings; import org.elasticsearch.util.json.JsonBuilder; import java.io.IOException; @@ -82,9 +83,9 @@ public class JsonStringFieldMapper extends JsonFieldMapper implements Js parseJsonField(builder, name, stringNode, parserContext); for (Iterator> propsIt = stringNode.getFields(); propsIt.hasNext();) { Map.Entry entry = propsIt.next(); - String propName = entry.getKey(); + String propName = Strings.toUnderscoreCase(entry.getKey()); JsonNode propNode = entry.getValue(); - if (propName.equals("nullValue")) { + if (propName.equals("null_value")) { builder.nullValue(propNode.getValueAsText()); } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonTypeParser.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonTypeParser.java index f506168ae31..e46d7e01a5e 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonTypeParser.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonTypeParser.java @@ -24,6 +24,7 @@ import org.codehaus.jackson.JsonNode; import org.codehaus.jackson.node.ObjectNode; import org.elasticsearch.index.analysis.AnalysisService; import org.elasticsearch.index.mapper.MapperParsingException; +import org.elasticsearch.util.Strings; /** * @author kimchy (shay.banon) @@ -53,7 +54,7 @@ public interface JsonTypeParser { } public JsonTypeParser typeParser(String type) { - return typeParsers.get(type); + return typeParsers.get(Strings.toUnderscoreCase(type)); } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonTypeParsers.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonTypeParsers.java index 5e66fcd5064..8ff7f89b590 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonTypeParsers.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/json/JsonTypeParsers.java @@ -23,6 +23,7 @@ import org.apache.lucene.document.Field; import org.codehaus.jackson.JsonNode; import org.codehaus.jackson.node.ObjectNode; import org.elasticsearch.index.mapper.MapperParsingException; +import org.elasticsearch.util.Strings; import org.elasticsearch.util.joda.FormatDateTimeFormatter; import org.elasticsearch.util.joda.Joda; @@ -40,9 +41,9 @@ public class JsonTypeParsers { parseJsonField(builder, name, numberNode, parserContext); for (Iterator> propsIt = numberNode.getFields(); propsIt.hasNext();) { Map.Entry entry = propsIt.next(); - String propName = entry.getKey(); + String propName = Strings.toUnderscoreCase(entry.getKey()); JsonNode propNode = entry.getValue(); - if (propName.equals("precisionStep") || propName.equals("precision_step")) { + if (propName.equals("precision_step")) { builder.precisionStep(nodeIntegerValue(propNode)); } } @@ -51,30 +52,30 @@ public class JsonTypeParsers { public static void parseJsonField(JsonFieldMapper.Builder builder, String name, ObjectNode fieldNode, JsonTypeParser.ParserContext parserContext) { for (Iterator> propsIt = fieldNode.getFields(); propsIt.hasNext();) { Map.Entry entry = propsIt.next(); - String propName = entry.getKey(); + String propName = Strings.toUnderscoreCase(entry.getKey()); JsonNode propNode = entry.getValue(); - if (propName.equals("indexName") || propName.equals("index_name")) { + if (propName.equals("index_name")) { builder.indexName(propNode.getTextValue()); } else if (propName.equals("store")) { builder.store(parseStore(name, propNode.getTextValue())); } else if (propName.equals("index")) { builder.index(parseIndex(name, propNode.getTextValue())); - } else if (propName.equals("termVector") || propName.equals("term_vector")) { + } else if (propName.equals("term_vector")) { builder.termVector(parseTermVector(name, propNode.getTextValue())); } else if (propName.equals("boost")) { builder.boost(nodeFloatValue(propNode)); - } else if (propName.equals("omitNorms") || propName.equals("omit_norms")) { + } else if (propName.equals("omit_norms")) { builder.omitNorms(nodeBooleanValue(propNode)); - } else if (propName.equals("omitTermFreqAndPositions") || propName.equals("omit_term_freq_and_positions")) { + } else if (propName.equals("omit_term_freq_and_positions")) { builder.omitTermFreqAndPositions(nodeBooleanValue(propNode)); - } else if (propName.equals("indexAnalyzer") || propName.equals("index_analyzer")) { + } else if (propName.equals("index_analyzer")) { builder.indexAnalyzer(parserContext.analysisService().analyzer(propNode.getTextValue())); - } else if (propName.equals("searchAnalyzer") || propName.equals("search_analyzer")) { + } else if (propName.equals("search_analyzer")) { builder.searchAnalyzer(parserContext.analysisService().analyzer(propNode.getTextValue())); } else if (propName.equals("analyzer")) { builder.indexAnalyzer(parserContext.analysisService().analyzer(propNode.getTextValue())); builder.searchAnalyzer(parserContext.analysisService().analyzer(propNode.getTextValue())); - } else if (propName.equals("includeInAll") || propName.equals("include_in_all")) { + } else if (propName.equals("include_in_all")) { builder.includeInAll(nodeBooleanValue(propNode)); } } @@ -90,6 +91,7 @@ public class JsonTypeParsers { } public static Field.TermVector parseTermVector(String fieldName, String termVector) throws MapperParsingException { + termVector = Strings.toUnderscoreCase(termVector); if ("no".equals(termVector)) { return Field.TermVector.NO; } else if ("yes".equals(termVector)) { @@ -106,6 +108,7 @@ public class JsonTypeParsers { } public static Field.Index parseIndex(String fieldName, String index) throws MapperParsingException { + index = Strings.toUnderscoreCase(index); if ("no".equals(index)) { return Field.Index.NO; } else if ("not_analyzed".equals(index)) { @@ -128,7 +131,8 @@ public class JsonTypeParsers { } public static JsonPath.Type parsePathType(String name, String path) throws MapperParsingException { - if ("justName".equals(path) || "just_name".equals(path)) { + path = Strings.toUnderscoreCase(path); + if ("just_name".equals(path)) { return JsonPath.Type.JUST_NAME; } else if ("full".equals(path)) { return JsonPath.Type.FULL;