Mapper: Allow to define CamelCase JSON fields in mapping definitions, closes #133.

This commit is contained in:
kimchy 2010-04-14 08:54:38 +03:00
parent cb7e92b0f8
commit 2d6de97069
12 changed files with 49 additions and 34 deletions

View File

@ -26,6 +26,7 @@ import org.codehaus.jackson.JsonToken;
import org.codehaus.jackson.node.ObjectNode; import org.codehaus.jackson.node.ObjectNode;
import org.elasticsearch.index.mapper.MapperParsingException; import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.util.Booleans; import org.elasticsearch.util.Booleans;
import org.elasticsearch.util.Strings;
import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.json.JsonBuilder;
import org.elasticsearch.util.lucene.Lucene; import org.elasticsearch.util.lucene.Lucene;
@ -102,9 +103,9 @@ public class JsonBooleanFieldMapper extends JsonFieldMapper<Boolean> {
parseJsonField(builder, name, booleanNode, parserContext); parseJsonField(builder, name, booleanNode, parserContext);
for (Iterator<Map.Entry<String, JsonNode>> propsIt = booleanNode.getFields(); propsIt.hasNext();) { for (Iterator<Map.Entry<String, JsonNode>> propsIt = booleanNode.getFields(); propsIt.hasNext();) {
Map.Entry<String, JsonNode> entry = propsIt.next(); Map.Entry<String, JsonNode> entry = propsIt.next();
String propName = entry.getKey(); String propName = Strings.toUnderscoreCase(entry.getKey());
JsonNode propNode = entry.getValue(); JsonNode propNode = entry.getValue();
if (propName.equals("nullValue") || propName.equals("null_value")) { if (propName.equals("null_value")) {
builder.nullValue(nodeBooleanValue(propNode)); builder.nullValue(nodeBooleanValue(propNode));
} }
} }

View File

@ -30,6 +30,7 @@ import org.elasticsearch.index.analysis.NamedAnalyzer;
import org.elasticsearch.index.analysis.NumericDateAnalyzer; import org.elasticsearch.index.analysis.NumericDateAnalyzer;
import org.elasticsearch.index.mapper.MapperParsingException; import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.util.Numbers; import org.elasticsearch.util.Numbers;
import org.elasticsearch.util.Strings;
import org.elasticsearch.util.joda.FormatDateTimeFormatter; import org.elasticsearch.util.joda.FormatDateTimeFormatter;
import org.elasticsearch.util.joda.Joda; import org.elasticsearch.util.joda.Joda;
import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.json.JsonBuilder;
@ -90,9 +91,9 @@ public class JsonDateFieldMapper extends JsonNumberFieldMapper<Long> {
parseNumberField(builder, name, dateNode, parserContext); parseNumberField(builder, name, dateNode, parserContext);
for (Iterator<Map.Entry<String, JsonNode>> propsIt = dateNode.getFields(); propsIt.hasNext();) { for (Iterator<Map.Entry<String, JsonNode>> propsIt = dateNode.getFields(); propsIt.hasNext();) {
Map.Entry<String, JsonNode> entry = propsIt.next(); Map.Entry<String, JsonNode> entry = propsIt.next();
String propName = entry.getKey(); String propName = Strings.toUnderscoreCase(entry.getKey());
JsonNode propNode = entry.getValue(); JsonNode propNode = entry.getValue();
if (propName.equals("nullValue") || propName.equals("null_value")) { if (propName.equals("null_value")) {
builder.nullValue(propNode.getValueAsText()); builder.nullValue(propNode.getValueAsText());
} else if (propName.equals("format")) { } else if (propName.equals("format")) {
builder.dateTimeFormatter(parseDateTimeFormatter(propName, propNode)); builder.dateTimeFormatter(parseDateTimeFormatter(propName, propNode));

View File

@ -28,6 +28,7 @@ import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.DocumentMapperParser; import org.elasticsearch.index.mapper.DocumentMapperParser;
import org.elasticsearch.index.mapper.MapperParsingException; import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.util.MapBuilder; import org.elasticsearch.util.MapBuilder;
import org.elasticsearch.util.Strings;
import org.elasticsearch.util.io.FastStringReader; import org.elasticsearch.util.io.FastStringReader;
import org.elasticsearch.util.json.Jackson; import org.elasticsearch.util.json.Jackson;
@ -117,7 +118,7 @@ public class JsonDocumentMapperParser implements DocumentMapperParser {
for (Iterator<Map.Entry<String, JsonNode>> fieldsIt = rootObj.getFields(); fieldsIt.hasNext();) { for (Iterator<Map.Entry<String, JsonNode>> fieldsIt = rootObj.getFields(); fieldsIt.hasNext();) {
Map.Entry<String, JsonNode> entry = fieldsIt.next(); Map.Entry<String, JsonNode> entry = fieldsIt.next();
String fieldName = entry.getKey(); String fieldName = Strings.toUnderscoreCase(entry.getKey());
JsonNode fieldNode = entry.getValue(); JsonNode fieldNode = entry.getValue();
if (JsonSourceFieldMapper.JSON_TYPE.equals(fieldName) || "sourceField".equals(fieldName)) { if (JsonSourceFieldMapper.JSON_TYPE.equals(fieldName) || "sourceField".equals(fieldName)) {
@ -178,7 +179,7 @@ public class JsonDocumentMapperParser implements DocumentMapperParser {
parseNumberField(builder, name, boostNode, parserContext); parseNumberField(builder, name, boostNode, parserContext);
for (Iterator<Map.Entry<String, JsonNode>> propsIt = boostNode.getFields(); propsIt.hasNext();) { for (Iterator<Map.Entry<String, JsonNode>> propsIt = boostNode.getFields(); propsIt.hasNext();) {
Map.Entry<String, JsonNode> entry = propsIt.next(); Map.Entry<String, JsonNode> entry = propsIt.next();
String propName = entry.getKey(); String propName = Strings.toUnderscoreCase(entry.getKey());
JsonNode propNode = entry.getValue(); JsonNode propNode = entry.getValue();
if (propName.equals("null_value")) { if (propName.equals("null_value")) {
builder.nullValue(nodeFloatValue(propNode)); builder.nullValue(nodeFloatValue(propNode));
@ -208,7 +209,7 @@ public class JsonDocumentMapperParser implements DocumentMapperParser {
parseJsonField(builder, builder.name, allNode, parserContext); parseJsonField(builder, builder.name, allNode, parserContext);
for (Iterator<Map.Entry<String, JsonNode>> fieldsIt = allNode.getFields(); fieldsIt.hasNext();) { for (Iterator<Map.Entry<String, JsonNode>> fieldsIt = allNode.getFields(); fieldsIt.hasNext();) {
Map.Entry<String, JsonNode> entry = fieldsIt.next(); Map.Entry<String, JsonNode> entry = fieldsIt.next();
String fieldName = entry.getKey(); String fieldName = Strings.toUnderscoreCase(entry.getKey());
JsonNode fieldNode = entry.getValue(); JsonNode fieldNode = entry.getValue();
if (fieldName.equals("enabled")) { if (fieldName.equals("enabled")) {
builder.enabled(nodeBooleanValue(fieldNode)); builder.enabled(nodeBooleanValue(fieldNode));
@ -222,7 +223,7 @@ public class JsonDocumentMapperParser implements DocumentMapperParser {
JsonSourceFieldMapper.Builder builder = source(); JsonSourceFieldMapper.Builder builder = source();
for (Iterator<Map.Entry<String, JsonNode>> fieldsIt = sourceNode.getFields(); fieldsIt.hasNext();) { for (Iterator<Map.Entry<String, JsonNode>> fieldsIt = sourceNode.getFields(); fieldsIt.hasNext();) {
Map.Entry<String, JsonNode> entry = fieldsIt.next(); Map.Entry<String, JsonNode> entry = fieldsIt.next();
String fieldName = entry.getKey(); String fieldName = Strings.toUnderscoreCase(entry.getKey());
JsonNode fieldNode = entry.getValue(); JsonNode fieldNode = entry.getValue();
if (fieldName.equals("enabled")) { if (fieldName.equals("enabled")) {
builder.enabled(nodeBooleanValue(fieldNode)); builder.enabled(nodeBooleanValue(fieldNode));

View File

@ -30,6 +30,7 @@ import org.elasticsearch.index.analysis.NamedAnalyzer;
import org.elasticsearch.index.analysis.NumericFloatAnalyzer; import org.elasticsearch.index.analysis.NumericFloatAnalyzer;
import org.elasticsearch.index.mapper.MapperParsingException; import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.util.Numbers; import org.elasticsearch.util.Numbers;
import org.elasticsearch.util.Strings;
import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.json.JsonBuilder;
import java.io.IOException; import java.io.IOException;
@ -80,9 +81,9 @@ public class JsonFloatFieldMapper extends JsonNumberFieldMapper<Float> {
parseNumberField(builder, name, floatNode, parserContext); parseNumberField(builder, name, floatNode, parserContext);
for (Iterator<Map.Entry<String, JsonNode>> propsIt = floatNode.getFields(); propsIt.hasNext();) { for (Iterator<Map.Entry<String, JsonNode>> propsIt = floatNode.getFields(); propsIt.hasNext();) {
Map.Entry<String, JsonNode> entry = propsIt.next(); Map.Entry<String, JsonNode> entry = propsIt.next();
String propName = entry.getKey(); String propName = Strings.toUnderscoreCase(entry.getKey());
JsonNode propNode = entry.getValue(); JsonNode propNode = entry.getValue();
if (propName.equals("nullValue") || propName.equals("null_value")) { if (propName.equals("null_value")) {
builder.nullValue(nodeFloatValue(propNode)); builder.nullValue(nodeFloatValue(propNode));
} }
} }

View File

@ -30,6 +30,7 @@ import org.elasticsearch.index.analysis.NamedAnalyzer;
import org.elasticsearch.index.analysis.NumericIntegerAnalyzer; import org.elasticsearch.index.analysis.NumericIntegerAnalyzer;
import org.elasticsearch.index.mapper.MapperParsingException; import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.util.Numbers; import org.elasticsearch.util.Numbers;
import org.elasticsearch.util.Strings;
import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.json.JsonBuilder;
import java.io.IOException; import java.io.IOException;
@ -80,9 +81,9 @@ public class JsonIntegerFieldMapper extends JsonNumberFieldMapper<Integer> {
parseNumberField(builder, name, integerNode, parserContext); parseNumberField(builder, name, integerNode, parserContext);
for (Iterator<Map.Entry<String, JsonNode>> propsIt = integerNode.getFields(); propsIt.hasNext();) { for (Iterator<Map.Entry<String, JsonNode>> propsIt = integerNode.getFields(); propsIt.hasNext();) {
Map.Entry<String, JsonNode> entry = propsIt.next(); Map.Entry<String, JsonNode> entry = propsIt.next();
String propName = entry.getKey(); String propName = Strings.toUnderscoreCase(entry.getKey());
JsonNode propNode = entry.getValue(); JsonNode propNode = entry.getValue();
if (propName.equals("nullValue")) { if (propName.equals("null_value")) {
builder.nullValue(nodeIntegerValue(propNode)); builder.nullValue(nodeIntegerValue(propNode));
} }
} }

View File

@ -30,6 +30,7 @@ import org.elasticsearch.index.analysis.NamedAnalyzer;
import org.elasticsearch.index.analysis.NumericLongAnalyzer; import org.elasticsearch.index.analysis.NumericLongAnalyzer;
import org.elasticsearch.index.mapper.MapperParsingException; import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.util.Numbers; import org.elasticsearch.util.Numbers;
import org.elasticsearch.util.Strings;
import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.json.JsonBuilder;
import java.io.IOException; import java.io.IOException;
@ -80,9 +81,9 @@ public class JsonLongFieldMapper extends JsonNumberFieldMapper<Long> {
parseNumberField(builder, name, longNode, parserContext); parseNumberField(builder, name, longNode, parserContext);
for (Iterator<Map.Entry<String, JsonNode>> propsIt = longNode.getFields(); propsIt.hasNext();) { for (Iterator<Map.Entry<String, JsonNode>> propsIt = longNode.getFields(); propsIt.hasNext();) {
Map.Entry<String, JsonNode> entry = propsIt.next(); Map.Entry<String, JsonNode> entry = propsIt.next();
String propName = entry.getKey(); String propName = Strings.toUnderscoreCase(entry.getKey());
JsonNode propNode = entry.getValue(); JsonNode propNode = entry.getValue();
if (propName.equals("nullValue")) { if (propName.equals("null_value")) {
builder.nullValue(nodeLongValue(propNode)); builder.nullValue(nodeLongValue(propNode));
} }
} }

View File

@ -26,6 +26,7 @@ import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.FieldMapperListener; import org.elasticsearch.index.mapper.FieldMapperListener;
import org.elasticsearch.index.mapper.MapperParsingException; import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.index.mapper.MergeMappingException; import org.elasticsearch.index.mapper.MergeMappingException;
import org.elasticsearch.util.Strings;
import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.json.JsonBuilder;
import java.io.IOException; import java.io.IOException;
@ -106,7 +107,7 @@ public class JsonMultiFieldMapper implements JsonMapper, JsonIncludeInAllMapper
JsonMultiFieldMapper.Builder builder = multiField(name); JsonMultiFieldMapper.Builder builder = multiField(name);
for (Iterator<Map.Entry<String, JsonNode>> fieldsIt = multiFieldNode.getFields(); fieldsIt.hasNext();) { for (Iterator<Map.Entry<String, JsonNode>> fieldsIt = multiFieldNode.getFields(); fieldsIt.hasNext();) {
Map.Entry<String, JsonNode> entry = fieldsIt.next(); Map.Entry<String, JsonNode> entry = fieldsIt.next();
String fieldName = entry.getKey(); String fieldName = Strings.toUnderscoreCase(entry.getKey());
JsonNode fieldNode = entry.getValue(); JsonNode fieldNode = entry.getValue();
if (fieldName.equals("path")) { if (fieldName.equals("path")) {
builder.pathType(parsePathType(name, fieldNode.getValueAsText())); builder.pathType(parsePathType(name, fieldNode.getValueAsText()));

View File

@ -27,6 +27,7 @@ import org.codehaus.jackson.node.ArrayNode;
import org.codehaus.jackson.node.ObjectNode; import org.codehaus.jackson.node.ObjectNode;
import org.elasticsearch.ElasticSearchIllegalStateException; import org.elasticsearch.ElasticSearchIllegalStateException;
import org.elasticsearch.index.mapper.*; import org.elasticsearch.index.mapper.*;
import org.elasticsearch.util.Strings;
import org.elasticsearch.util.concurrent.ThreadSafe; import org.elasticsearch.util.concurrent.ThreadSafe;
import org.elasticsearch.util.joda.FormatDateTimeFormatter; import org.elasticsearch.util.joda.FormatDateTimeFormatter;
import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.json.JsonBuilder;
@ -160,7 +161,7 @@ public class JsonObjectMapper implements JsonMapper, JsonIncludeInAllMapper {
JsonObjectMapper.Builder builder = object(name); JsonObjectMapper.Builder builder = object(name);
for (Iterator<Entry<String, JsonNode>> fieldsIt = objectNode.getFields(); fieldsIt.hasNext();) { for (Iterator<Entry<String, JsonNode>> fieldsIt = objectNode.getFields(); fieldsIt.hasNext();) {
Map.Entry<String, JsonNode> entry = fieldsIt.next(); Map.Entry<String, JsonNode> entry = fieldsIt.next();
String fieldName = entry.getKey(); String fieldName = Strings.toUnderscoreCase(entry.getKey());
JsonNode fieldNode = entry.getValue(); JsonNode fieldNode = entry.getValue();
if (fieldName.equals("dynamic")) { if (fieldName.equals("dynamic")) {
builder.dynamic(nodeBooleanValue(fieldNode)); builder.dynamic(nodeBooleanValue(fieldNode));
@ -169,7 +170,7 @@ public class JsonObjectMapper implements JsonMapper, JsonIncludeInAllMapper {
if (!type.equals("object")) { if (!type.equals("object")) {
throw new MapperParsingException("Trying to parse an object but has a different type [" + type + "] for [" + name + "]"); 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<FormatDateTimeFormatter> dateTimeFormatters = newArrayList(); List<FormatDateTimeFormatter> dateTimeFormatters = newArrayList();
if (fieldNode.isArray()) { if (fieldNode.isArray()) {
for (JsonNode node1 : (ArrayNode) fieldNode) { for (JsonNode node1 : (ArrayNode) fieldNode) {
@ -191,7 +192,7 @@ public class JsonObjectMapper implements JsonMapper, JsonIncludeInAllMapper {
builder.pathType(parsePathType(name, fieldNode.getValueAsText())); builder.pathType(parsePathType(name, fieldNode.getValueAsText()));
} else if (fieldName.equals("properties")) { } else if (fieldName.equals("properties")) {
parseProperties(builder, (ObjectNode) fieldNode, parserContext); 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)); builder.includeInAll(nodeBooleanValue(fieldNode));
} }
} }

View File

@ -30,6 +30,7 @@ import org.elasticsearch.index.analysis.NamedAnalyzer;
import org.elasticsearch.index.analysis.NumericIntegerAnalyzer; import org.elasticsearch.index.analysis.NumericIntegerAnalyzer;
import org.elasticsearch.index.mapper.MapperParsingException; import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.util.Numbers; import org.elasticsearch.util.Numbers;
import org.elasticsearch.util.Strings;
import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.json.JsonBuilder;
import java.io.IOException; import java.io.IOException;
@ -80,9 +81,9 @@ public class JsonShortFieldMapper extends JsonNumberFieldMapper<Short> {
parseNumberField(builder, name, shortNode, parserContext); parseNumberField(builder, name, shortNode, parserContext);
for (Iterator<Map.Entry<String, JsonNode>> propsIt = shortNode.getFields(); propsIt.hasNext();) { for (Iterator<Map.Entry<String, JsonNode>> propsIt = shortNode.getFields(); propsIt.hasNext();) {
Map.Entry<String, JsonNode> entry = propsIt.next(); Map.Entry<String, JsonNode> entry = propsIt.next();
String propName = entry.getKey(); String propName = Strings.toUnderscoreCase(entry.getKey());
JsonNode propNode = entry.getValue(); JsonNode propNode = entry.getValue();
if (propName.equals("nullValue") || propName.equals("null_value")) { if (propName.equals("null_value")) {
builder.nullValue(nodeShortValue(propNode)); builder.nullValue(nodeShortValue(propNode));
} }
} }

View File

@ -26,6 +26,7 @@ import org.codehaus.jackson.JsonToken;
import org.codehaus.jackson.node.ObjectNode; import org.codehaus.jackson.node.ObjectNode;
import org.elasticsearch.index.analysis.NamedAnalyzer; import org.elasticsearch.index.analysis.NamedAnalyzer;
import org.elasticsearch.index.mapper.MapperParsingException; import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.util.Strings;
import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.json.JsonBuilder;
import java.io.IOException; import java.io.IOException;
@ -82,9 +83,9 @@ public class JsonStringFieldMapper extends JsonFieldMapper<String> implements Js
parseJsonField(builder, name, stringNode, parserContext); parseJsonField(builder, name, stringNode, parserContext);
for (Iterator<Map.Entry<String, JsonNode>> propsIt = stringNode.getFields(); propsIt.hasNext();) { for (Iterator<Map.Entry<String, JsonNode>> propsIt = stringNode.getFields(); propsIt.hasNext();) {
Map.Entry<String, JsonNode> entry = propsIt.next(); Map.Entry<String, JsonNode> entry = propsIt.next();
String propName = entry.getKey(); String propName = Strings.toUnderscoreCase(entry.getKey());
JsonNode propNode = entry.getValue(); JsonNode propNode = entry.getValue();
if (propName.equals("nullValue")) { if (propName.equals("null_value")) {
builder.nullValue(propNode.getValueAsText()); builder.nullValue(propNode.getValueAsText());
} }
} }

View File

@ -24,6 +24,7 @@ import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.node.ObjectNode; import org.codehaus.jackson.node.ObjectNode;
import org.elasticsearch.index.analysis.AnalysisService; import org.elasticsearch.index.analysis.AnalysisService;
import org.elasticsearch.index.mapper.MapperParsingException; import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.util.Strings;
/** /**
* @author kimchy (shay.banon) * @author kimchy (shay.banon)
@ -53,7 +54,7 @@ public interface JsonTypeParser {
} }
public JsonTypeParser typeParser(String type) { public JsonTypeParser typeParser(String type) {
return typeParsers.get(type); return typeParsers.get(Strings.toUnderscoreCase(type));
} }
} }

View File

@ -23,6 +23,7 @@ import org.apache.lucene.document.Field;
import org.codehaus.jackson.JsonNode; import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.node.ObjectNode; import org.codehaus.jackson.node.ObjectNode;
import org.elasticsearch.index.mapper.MapperParsingException; import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.util.Strings;
import org.elasticsearch.util.joda.FormatDateTimeFormatter; import org.elasticsearch.util.joda.FormatDateTimeFormatter;
import org.elasticsearch.util.joda.Joda; import org.elasticsearch.util.joda.Joda;
@ -40,9 +41,9 @@ public class JsonTypeParsers {
parseJsonField(builder, name, numberNode, parserContext); parseJsonField(builder, name, numberNode, parserContext);
for (Iterator<Map.Entry<String, JsonNode>> propsIt = numberNode.getFields(); propsIt.hasNext();) { for (Iterator<Map.Entry<String, JsonNode>> propsIt = numberNode.getFields(); propsIt.hasNext();) {
Map.Entry<String, JsonNode> entry = propsIt.next(); Map.Entry<String, JsonNode> entry = propsIt.next();
String propName = entry.getKey(); String propName = Strings.toUnderscoreCase(entry.getKey());
JsonNode propNode = entry.getValue(); JsonNode propNode = entry.getValue();
if (propName.equals("precisionStep") || propName.equals("precision_step")) { if (propName.equals("precision_step")) {
builder.precisionStep(nodeIntegerValue(propNode)); 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) { public static void parseJsonField(JsonFieldMapper.Builder builder, String name, ObjectNode fieldNode, JsonTypeParser.ParserContext parserContext) {
for (Iterator<Map.Entry<String, JsonNode>> propsIt = fieldNode.getFields(); propsIt.hasNext();) { for (Iterator<Map.Entry<String, JsonNode>> propsIt = fieldNode.getFields(); propsIt.hasNext();) {
Map.Entry<String, JsonNode> entry = propsIt.next(); Map.Entry<String, JsonNode> entry = propsIt.next();
String propName = entry.getKey(); String propName = Strings.toUnderscoreCase(entry.getKey());
JsonNode propNode = entry.getValue(); JsonNode propNode = entry.getValue();
if (propName.equals("indexName") || propName.equals("index_name")) { if (propName.equals("index_name")) {
builder.indexName(propNode.getTextValue()); builder.indexName(propNode.getTextValue());
} else if (propName.equals("store")) { } else if (propName.equals("store")) {
builder.store(parseStore(name, propNode.getTextValue())); builder.store(parseStore(name, propNode.getTextValue()));
} else if (propName.equals("index")) { } else if (propName.equals("index")) {
builder.index(parseIndex(name, propNode.getTextValue())); 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())); builder.termVector(parseTermVector(name, propNode.getTextValue()));
} else if (propName.equals("boost")) { } else if (propName.equals("boost")) {
builder.boost(nodeFloatValue(propNode)); builder.boost(nodeFloatValue(propNode));
} else if (propName.equals("omitNorms") || propName.equals("omit_norms")) { } else if (propName.equals("omit_norms")) {
builder.omitNorms(nodeBooleanValue(propNode)); 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)); 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())); 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())); builder.searchAnalyzer(parserContext.analysisService().analyzer(propNode.getTextValue()));
} else if (propName.equals("analyzer")) { } else if (propName.equals("analyzer")) {
builder.indexAnalyzer(parserContext.analysisService().analyzer(propNode.getTextValue())); builder.indexAnalyzer(parserContext.analysisService().analyzer(propNode.getTextValue()));
builder.searchAnalyzer(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)); builder.includeInAll(nodeBooleanValue(propNode));
} }
} }
@ -90,6 +91,7 @@ public class JsonTypeParsers {
} }
public static Field.TermVector parseTermVector(String fieldName, String termVector) throws MapperParsingException { public static Field.TermVector parseTermVector(String fieldName, String termVector) throws MapperParsingException {
termVector = Strings.toUnderscoreCase(termVector);
if ("no".equals(termVector)) { if ("no".equals(termVector)) {
return Field.TermVector.NO; return Field.TermVector.NO;
} else if ("yes".equals(termVector)) { } else if ("yes".equals(termVector)) {
@ -106,6 +108,7 @@ public class JsonTypeParsers {
} }
public static Field.Index parseIndex(String fieldName, String index) throws MapperParsingException { public static Field.Index parseIndex(String fieldName, String index) throws MapperParsingException {
index = Strings.toUnderscoreCase(index);
if ("no".equals(index)) { if ("no".equals(index)) {
return Field.Index.NO; return Field.Index.NO;
} else if ("not_analyzed".equals(index)) { } else if ("not_analyzed".equals(index)) {
@ -128,7 +131,8 @@ public class JsonTypeParsers {
} }
public static JsonPath.Type parsePathType(String name, String path) throws MapperParsingException { 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; return JsonPath.Type.JUST_NAME;
} else if ("full".equals(path)) { } else if ("full".equals(path)) {
return JsonPath.Type.FULL; return JsonPath.Type.FULL;