Merge pull request #11141 from jpountz/fix/fieldnameanalyzer_leniency

Mappings: Make FieldNameAnalyzer less lenient.
This commit is contained in:
Adrien Grand 2015-05-15 16:41:44 +02:00
commit c5e74a8d72
2 changed files with 7 additions and 5 deletions

View File

@ -63,7 +63,9 @@ public final class FieldNameAnalyzer extends DelegatingAnalyzerWrapper {
if (analyzer != null) { if (analyzer != null) {
return analyzer; return analyzer;
} }
return defaultAnalyzer; // Don't be lenient here and return the default analyzer
// Fields need to be explicitly added
throw new IllegalArgumentException("Field [" + name + "] has no associated analyzer");
} }
/** /**
@ -72,9 +74,11 @@ public final class FieldNameAnalyzer extends DelegatingAnalyzerWrapper {
public FieldNameAnalyzer copyAndAddAll(Collection<? extends Map.Entry<String, Analyzer>> mappers) { public FieldNameAnalyzer copyAndAddAll(Collection<? extends Map.Entry<String, Analyzer>> mappers) {
CopyOnWriteHashMap<String, Analyzer> analyzers = this.analyzers; CopyOnWriteHashMap<String, Analyzer> analyzers = this.analyzers;
for (Map.Entry<String, Analyzer> entry : mappers) { for (Map.Entry<String, Analyzer> entry : mappers) {
if (entry.getValue() != null) { Analyzer analyzer = entry.getValue();
analyzers = analyzers.copyAndPut(entry.getKey(), entry.getValue()); if (analyzer == null) {
analyzer = defaultAnalyzer;
} }
analyzers = analyzers.copyAndPut(entry.getKey(), analyzer);
} }
return new FieldNameAnalyzer(analyzers, defaultAnalyzer); return new FieldNameAnalyzer(analyzers, defaultAnalyzer);
} }

View File

@ -19,8 +19,6 @@
package org.elasticsearch.index.mapper; package org.elasticsearch.index.mapper;
import java.util.Objects;
import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.DelegatingAnalyzerWrapper; import org.apache.lucene.analysis.DelegatingAnalyzerWrapper;
import org.elasticsearch.index.analysis.FieldNameAnalyzer; import org.elasticsearch.index.analysis.FieldNameAnalyzer;