From e6bd3f269359140f2b704aeb59f921585e54f4f8 Mon Sep 17 00:00:00 2001 From: kimchy Date: Mon, 12 Jul 2010 23:18:32 +0300 Subject: [PATCH] Put Mapping: Fail when an analyzer is specified that was not configured, closes #252. --- .../mapper/xcontent/XContentTypeParsers.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/XContentTypeParsers.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/XContentTypeParsers.java index c049228dfa7..8ed4696ad9f 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/XContentTypeParsers.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/XContentTypeParsers.java @@ -23,6 +23,7 @@ import org.apache.lucene.document.Field; import org.elasticsearch.common.Strings; import org.elasticsearch.common.joda.FormatDateTimeFormatter; import org.elasticsearch.common.joda.Joda; +import org.elasticsearch.index.analysis.NamedAnalyzer; import org.elasticsearch.index.mapper.MapperParsingException; import java.util.Map; @@ -64,12 +65,24 @@ public class XContentTypeParsers { } else if (propName.equals("omit_term_freq_and_positions")) { builder.omitTermFreqAndPositions(nodeBooleanValue(propNode)); } else if (propName.equals("index_analyzer")) { - builder.indexAnalyzer(parserContext.analysisService().analyzer(propNode.toString())); + NamedAnalyzer analyzer = parserContext.analysisService().analyzer(propNode.toString()); + if (analyzer == null) { + throw new MapperParsingException("Analyzer [" + propNode.toString() + "] not found for field [" + name + "]"); + } + builder.indexAnalyzer(analyzer); } else if (propName.equals("search_analyzer")) { - builder.searchAnalyzer(parserContext.analysisService().analyzer(propNode.toString())); + NamedAnalyzer analyzer = parserContext.analysisService().analyzer(propNode.toString()); + if (analyzer == null) { + throw new MapperParsingException("Analyzer [" + propNode.toString() + "] not found for field [" + name + "]"); + } + builder.searchAnalyzer(analyzer); } else if (propName.equals("analyzer")) { - builder.indexAnalyzer(parserContext.analysisService().analyzer(propNode.toString())); - builder.searchAnalyzer(parserContext.analysisService().analyzer(propNode.toString())); + NamedAnalyzer analyzer = parserContext.analysisService().analyzer(propNode.toString()); + if (analyzer == null) { + throw new MapperParsingException("Analyzer [" + propNode.toString() + "] not found for field [" + name + "]"); + } + builder.indexAnalyzer(analyzer); + builder.searchAnalyzer(analyzer); } else if (propName.equals("include_in_all")) { builder.includeInAll(nodeBooleanValue(propNode)); }