Change IndexAnalyzers default analyzer access (#42011)
Currently IndexAnalyzers keeps the three default as separate class members although they should refer to the same analyzers held in the additional analyzers map under the default names. This assumption should be made more explicit by keeping all analyzers in the map. This change adapts the constructor to check all the default entries are there and the getters to reach into the map with the default names when needed.
This commit is contained in:
parent
cd5f1b53e8
commit
3e59c31a12
|
@ -195,7 +195,7 @@ public class MetaDataIndexUpgradeService {
|
|||
}
|
||||
};
|
||||
try (IndexAnalyzers fakeIndexAnalzyers =
|
||||
new IndexAnalyzers(indexSettings, fakeDefault, fakeDefault, fakeDefault, analyzerMap, analyzerMap, analyzerMap)) {
|
||||
new IndexAnalyzers(indexSettings, analyzerMap, analyzerMap, analyzerMap)) {
|
||||
MapperService mapperService = new MapperService(indexSettings, fakeIndexAnalzyers, xContentRegistry, similarityService,
|
||||
mapperRegistry, () -> null);
|
||||
mapperService.merge(indexMetaData, MapperService.MergeReason.MAPPING_RECOVERY);
|
||||
|
|
|
@ -52,6 +52,11 @@ public final class AnalysisRegistry implements Closeable {
|
|||
public static final String INDEX_ANALYSIS_CHAR_FILTER = "index.analysis.char_filter";
|
||||
public static final String INDEX_ANALYSIS_FILTER = "index.analysis.filter";
|
||||
public static final String INDEX_ANALYSIS_TOKENIZER = "index.analysis.tokenizer";
|
||||
|
||||
public static final String DEFAULT_ANALYZER_NAME = "default";
|
||||
public static final String DEFAULT_SEARCH_ANALYZER_NAME = "default_search";
|
||||
public static final String DEFAULT_SEARCH_QUOTED_ANALYZER_NAME = "default_search_quoted";
|
||||
|
||||
private final PrebuiltAnalysis prebuiltAnalysis;
|
||||
private final Map<String, Analyzer> cachedAnalyzer = new ConcurrentHashMap<>();
|
||||
|
||||
|
@ -442,37 +447,29 @@ public final class AnalysisRegistry implements Closeable {
|
|||
"whitespace", () -> new WhitespaceTokenizer(), tokenFilterFactoryFactories, charFilterFactoryFactories);
|
||||
}
|
||||
|
||||
if (!analyzers.containsKey("default")) {
|
||||
NamedAnalyzer defaultAnalyzer = produceAnalyzer("default", new StandardAnalyzerProvider(indexSettings, null, "default",
|
||||
Settings.Builder.EMPTY_SETTINGS), tokenFilterFactoryFactories, charFilterFactoryFactories, tokenizerFactoryFactories);
|
||||
analyzers.put("default", defaultAnalyzer);
|
||||
if (!analyzers.containsKey(DEFAULT_ANALYZER_NAME)) {
|
||||
analyzers.put(DEFAULT_ANALYZER_NAME,
|
||||
produceAnalyzer(DEFAULT_ANALYZER_NAME,
|
||||
new StandardAnalyzerProvider(indexSettings, null, DEFAULT_ANALYZER_NAME, Settings.Builder.EMPTY_SETTINGS),
|
||||
tokenFilterFactoryFactories, charFilterFactoryFactories, tokenizerFactoryFactories));
|
||||
}
|
||||
if (!analyzers.containsKey("default_search")) {
|
||||
analyzers.put("default_search", analyzers.get("default"));
|
||||
}
|
||||
if (!analyzers.containsKey("default_search_quoted")) {
|
||||
analyzers.put("default_search_quoted", analyzers.get("default_search"));
|
||||
}
|
||||
|
||||
NamedAnalyzer defaultAnalyzer = analyzers.get("default");
|
||||
NamedAnalyzer defaultAnalyzer = analyzers.get(DEFAULT_ANALYZER_NAME);
|
||||
if (defaultAnalyzer == null) {
|
||||
throw new IllegalArgumentException("no default analyzer configured");
|
||||
}
|
||||
defaultAnalyzer.checkAllowedInMode(AnalysisMode.ALL);
|
||||
|
||||
if (analyzers.containsKey("default_index")) {
|
||||
throw new IllegalArgumentException("setting [index.analysis.analyzer.default_index] is not supported anymore, use " +
|
||||
"[index.analysis.analyzer.default] instead for index [" + index.getName() + "]");
|
||||
}
|
||||
NamedAnalyzer defaultSearchAnalyzer = analyzers.getOrDefault("default_search", defaultAnalyzer);
|
||||
NamedAnalyzer defaultSearchQuoteAnalyzer = analyzers.getOrDefault("default_search_quote", defaultSearchAnalyzer);
|
||||
|
||||
for (Map.Entry<String, NamedAnalyzer> analyzer : analyzers.entrySet()) {
|
||||
if (analyzer.getKey().startsWith("_")) {
|
||||
throw new IllegalArgumentException("analyzer name must not start with '_'. got \"" + analyzer.getKey() + "\"");
|
||||
}
|
||||
}
|
||||
return new IndexAnalyzers(indexSettings, defaultAnalyzer, defaultSearchAnalyzer, defaultSearchQuoteAnalyzer, analyzers, normalizers,
|
||||
whitespaceNormalizers);
|
||||
return new IndexAnalyzers(indexSettings, analyzers, normalizers, whitespaceNormalizers);
|
||||
}
|
||||
|
||||
private static NamedAnalyzer produceAnalyzer(String name, AnalyzerProvider<?> analyzerFactory,
|
||||
|
|
|
@ -25,9 +25,13 @@ import org.elasticsearch.index.IndexSettings;
|
|||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static java.util.Collections.unmodifiableMap;
|
||||
import static org.elasticsearch.index.analysis.AnalysisRegistry.DEFAULT_ANALYZER_NAME;
|
||||
import static org.elasticsearch.index.analysis.AnalysisRegistry.DEFAULT_SEARCH_ANALYZER_NAME;
|
||||
import static org.elasticsearch.index.analysis.AnalysisRegistry.DEFAULT_SEARCH_QUOTED_ANALYZER_NAME;
|
||||
|
||||
/**
|
||||
* IndexAnalyzers contains a name to analyzer mapping for a specific index.
|
||||
|
@ -37,23 +41,18 @@ import static java.util.Collections.unmodifiableMap;
|
|||
* @see AnalysisRegistry
|
||||
*/
|
||||
public final class IndexAnalyzers extends AbstractIndexComponent implements Closeable {
|
||||
private final NamedAnalyzer defaultIndexAnalyzer;
|
||||
private final NamedAnalyzer defaultSearchAnalyzer;
|
||||
private final NamedAnalyzer defaultSearchQuoteAnalyzer;
|
||||
private final Map<String, NamedAnalyzer> analyzers;
|
||||
private final Map<String, NamedAnalyzer> normalizers;
|
||||
private final Map<String, NamedAnalyzer> whitespaceNormalizers;
|
||||
|
||||
public IndexAnalyzers(IndexSettings indexSettings, NamedAnalyzer defaultIndexAnalyzer, NamedAnalyzer defaultSearchAnalyzer,
|
||||
NamedAnalyzer defaultSearchQuoteAnalyzer, Map<String, NamedAnalyzer> analyzers,
|
||||
Map<String, NamedAnalyzer> normalizers, Map<String, NamedAnalyzer> whitespaceNormalizers) {
|
||||
public IndexAnalyzers(IndexSettings indexSettings, Map<String, NamedAnalyzer> analyzers, Map<String, NamedAnalyzer> normalizers,
|
||||
Map<String, NamedAnalyzer> whitespaceNormalizers) {
|
||||
super(indexSettings);
|
||||
if (defaultIndexAnalyzer.name().equals("default") == false) {
|
||||
throw new IllegalStateException("default analyzer must have the name [default] but was: [" + defaultIndexAnalyzer.name() + "]");
|
||||
Objects.requireNonNull(analyzers.get(DEFAULT_ANALYZER_NAME), "the default analyzer must be set");
|
||||
if (analyzers.get(DEFAULT_ANALYZER_NAME).name().equals(DEFAULT_ANALYZER_NAME) == false) {
|
||||
throw new IllegalStateException(
|
||||
"default analyzer must have the name [default] but was: [" + analyzers.get(DEFAULT_ANALYZER_NAME).name() + "]");
|
||||
}
|
||||
this.defaultIndexAnalyzer = defaultIndexAnalyzer;
|
||||
this.defaultSearchAnalyzer = defaultSearchAnalyzer;
|
||||
this.defaultSearchQuoteAnalyzer = defaultSearchQuoteAnalyzer;
|
||||
this.analyzers = unmodifiableMap(analyzers);
|
||||
this.normalizers = unmodifiableMap(normalizers);
|
||||
this.whitespaceNormalizers = unmodifiableMap(whitespaceNormalizers);
|
||||
|
@ -84,21 +83,21 @@ public final class IndexAnalyzers extends AbstractIndexComponent implements Clos
|
|||
* Returns the default index analyzer for this index
|
||||
*/
|
||||
public NamedAnalyzer getDefaultIndexAnalyzer() {
|
||||
return defaultIndexAnalyzer;
|
||||
return analyzers.get(DEFAULT_ANALYZER_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default search analyzer for this index
|
||||
* Returns the default search analyzer for this index. If not set, this will return the default analyzer
|
||||
*/
|
||||
public NamedAnalyzer getDefaultSearchAnalyzer() {
|
||||
return defaultSearchAnalyzer;
|
||||
return analyzers.getOrDefault(DEFAULT_SEARCH_ANALYZER_NAME, getDefaultIndexAnalyzer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default search quote analyzer for this index
|
||||
*/
|
||||
public NamedAnalyzer getDefaultSearchQuoteAnalyzer() {
|
||||
return defaultSearchQuoteAnalyzer;
|
||||
return analyzers.getOrDefault(DEFAULT_SEARCH_QUOTED_ANALYZER_NAME, getDefaultSearchAnalyzer());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -123,9 +123,9 @@ public class AnalysisRegistryTests extends ESTestCase {
|
|||
Analyzer analyzer = new CustomAnalyzer("tokenizerName", null, new CharFilterFactory[0], new TokenFilterFactory[] { tokenFilter });
|
||||
MapperException ex = expectThrows(MapperException.class,
|
||||
() -> emptyRegistry.build(IndexSettingsModule.newIndexSettings("index", settings),
|
||||
singletonMap("default", new PreBuiltAnalyzerProvider("my_analyzer", AnalyzerScope.INDEX, analyzer)), emptyMap(),
|
||||
singletonMap("default", new PreBuiltAnalyzerProvider("default", AnalyzerScope.INDEX, analyzer)), emptyMap(),
|
||||
emptyMap(), emptyMap(), emptyMap()));
|
||||
assertEquals("analyzer [my_analyzer] contains filters [my_filter] that are not allowed to run in all mode.", ex.getMessage());
|
||||
assertEquals("analyzer [default] contains filters [my_filter] that are not allowed to run in all mode.", ex.getMessage());
|
||||
}
|
||||
|
||||
public void testOverrideDefaultIndexAnalyzerIsUnsupported() {
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.index.analysis;
|
||||
|
||||
import org.apache.lucene.analysis.standard.StandardAnalyzer;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.test.IndexSettingsModule;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class IndexAnalyzersTests extends ESTestCase {
|
||||
|
||||
/**
|
||||
* test the checks in the constructor
|
||||
*/
|
||||
public void testAnalyzerMapChecks() {
|
||||
Map<String, NamedAnalyzer> analyzers = new HashMap<>();
|
||||
{
|
||||
NullPointerException ex = expectThrows(NullPointerException.class,
|
||||
() -> new IndexAnalyzers(IndexSettingsModule.newIndexSettings("index", Settings.EMPTY), analyzers,
|
||||
Collections.emptyMap(), Collections.emptyMap()));
|
||||
assertEquals("the default analyzer must be set", ex.getMessage());
|
||||
}
|
||||
{
|
||||
analyzers.put(AnalysisRegistry.DEFAULT_ANALYZER_NAME,
|
||||
new NamedAnalyzer("otherName", AnalyzerScope.INDEX, new StandardAnalyzer()));
|
||||
IllegalStateException ex = expectThrows(IllegalStateException.class,
|
||||
() -> new IndexAnalyzers(IndexSettingsModule.newIndexSettings("index", Settings.EMPTY), analyzers,
|
||||
Collections.emptyMap(), Collections.emptyMap()));
|
||||
assertEquals("default analyzer must have the name [default] but was: [otherName]", ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void testAnalyzerDefaults() throws IOException {
|
||||
Map<String, NamedAnalyzer> analyzers = new HashMap<>();
|
||||
NamedAnalyzer analyzer = new NamedAnalyzer("default", AnalyzerScope.INDEX, new StandardAnalyzer());
|
||||
analyzers.put(AnalysisRegistry.DEFAULT_ANALYZER_NAME, analyzer);
|
||||
|
||||
// if only "default" is set in the map, all getters should return the same analyzer
|
||||
try (IndexAnalyzers indexAnalyzers = new IndexAnalyzers(IndexSettingsModule.newIndexSettings("index", Settings.EMPTY), analyzers,
|
||||
Collections.emptyMap(), Collections.emptyMap())) {
|
||||
assertSame(analyzer, indexAnalyzers.getDefaultIndexAnalyzer());
|
||||
assertSame(analyzer, indexAnalyzers.getDefaultSearchAnalyzer());
|
||||
assertSame(analyzer, indexAnalyzers.getDefaultSearchQuoteAnalyzer());
|
||||
}
|
||||
|
||||
analyzers.put(AnalysisRegistry.DEFAULT_SEARCH_ANALYZER_NAME,
|
||||
new NamedAnalyzer("my_search_analyzer", AnalyzerScope.INDEX, new StandardAnalyzer()));
|
||||
try (IndexAnalyzers indexAnalyzers = new IndexAnalyzers(IndexSettingsModule.newIndexSettings("index", Settings.EMPTY), analyzers,
|
||||
Collections.emptyMap(), Collections.emptyMap())) {
|
||||
assertSame(analyzer, indexAnalyzers.getDefaultIndexAnalyzer());
|
||||
assertEquals("my_search_analyzer", indexAnalyzers.getDefaultSearchAnalyzer().name());
|
||||
assertEquals("my_search_analyzer", indexAnalyzers.getDefaultSearchQuoteAnalyzer().name());
|
||||
}
|
||||
|
||||
analyzers.put(AnalysisRegistry.DEFAULT_SEARCH_QUOTED_ANALYZER_NAME,
|
||||
new NamedAnalyzer("my_search_quote_analyzer", AnalyzerScope.INDEX, new StandardAnalyzer()));
|
||||
try (IndexAnalyzers indexAnalyzers = new IndexAnalyzers(IndexSettingsModule.newIndexSettings("index", Settings.EMPTY), analyzers,
|
||||
Collections.emptyMap(), Collections.emptyMap())) {
|
||||
assertSame(analyzer, indexAnalyzers.getDefaultIndexAnalyzer());
|
||||
assertEquals("my_search_analyzer", indexAnalyzers.getDefaultSearchAnalyzer().name());
|
||||
assertEquals("my_search_quote_analyzer", indexAnalyzers.getDefaultSearchQuoteAnalyzer().name());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -40,6 +40,9 @@ import java.util.Collections;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.elasticsearch.index.analysis.AnalysisRegistry.DEFAULT_ANALYZER_NAME;
|
||||
import static org.elasticsearch.index.analysis.AnalysisRegistry.DEFAULT_SEARCH_ANALYZER_NAME;
|
||||
import static org.elasticsearch.index.analysis.AnalysisRegistry.DEFAULT_SEARCH_QUOTED_ANALYZER_NAME;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
|
@ -57,22 +60,20 @@ public class TypeParsersTests extends ESTestCase {
|
|||
Mapper.TypeParser.ParserContext parserContext = mock(Mapper.TypeParser.ParserContext.class);
|
||||
|
||||
// check AnalysisMode.ALL works
|
||||
Map<String, NamedAnalyzer> analyzers = new HashMap<>();
|
||||
Map<String, NamedAnalyzer> analyzers = defaultAnalyzers();
|
||||
analyzers.put("my_analyzer",
|
||||
new NamedAnalyzer("my_named_analyzer", AnalyzerScope.INDEX, createAnalyzerWithMode("my_analyzer", AnalysisMode.ALL)));
|
||||
|
||||
IndexAnalyzers indexAnalyzers = new IndexAnalyzers(indexSettings, new NamedAnalyzer("default", AnalyzerScope.INDEX, null), null,
|
||||
null, analyzers, Collections.emptyMap(), Collections.emptyMap());
|
||||
IndexAnalyzers indexAnalyzers = new IndexAnalyzers(indexSettings, analyzers, Collections.emptyMap(), Collections.emptyMap());
|
||||
when(parserContext.getIndexAnalyzers()).thenReturn(indexAnalyzers);
|
||||
TypeParsers.parseTextField(builder, "name", new HashMap<>(fieldNode), parserContext);
|
||||
|
||||
// check that "analyzer" set to something that only supports AnalysisMode.SEARCH_TIME or AnalysisMode.INDEX_TIME is blocked
|
||||
AnalysisMode mode = randomFrom(AnalysisMode.SEARCH_TIME, AnalysisMode.INDEX_TIME);
|
||||
analyzers = new HashMap<>();
|
||||
analyzers = defaultAnalyzers();
|
||||
analyzers.put("my_analyzer", new NamedAnalyzer("my_named_analyzer", AnalyzerScope.INDEX,
|
||||
createAnalyzerWithMode("my_analyzer", mode)));
|
||||
indexAnalyzers = new IndexAnalyzers(indexSettings, new NamedAnalyzer("default", AnalyzerScope.INDEX, null), null, null, analyzers,
|
||||
Collections.emptyMap(), Collections.emptyMap());
|
||||
indexAnalyzers = new IndexAnalyzers(indexSettings, analyzers, Collections.emptyMap(), Collections.emptyMap());
|
||||
when(parserContext.getIndexAnalyzers()).thenReturn(indexAnalyzers);
|
||||
MapperException ex = expectThrows(MapperException.class,
|
||||
() -> TypeParsers.parseTextField(builder, "name", new HashMap<>(fieldNode), parserContext));
|
||||
|
@ -80,6 +81,14 @@ public class TypeParsersTests extends ESTestCase {
|
|||
ex.getMessage());
|
||||
}
|
||||
|
||||
private static Map<String, NamedAnalyzer> defaultAnalyzers() {
|
||||
Map<String, NamedAnalyzer> analyzers = new HashMap<>();
|
||||
analyzers.put(DEFAULT_ANALYZER_NAME, new NamedAnalyzer("default", AnalyzerScope.INDEX, null));
|
||||
analyzers.put(DEFAULT_SEARCH_ANALYZER_NAME, new NamedAnalyzer("default", AnalyzerScope.INDEX, null));
|
||||
analyzers.put(DEFAULT_SEARCH_QUOTED_ANALYZER_NAME, new NamedAnalyzer("default", AnalyzerScope.INDEX, null));
|
||||
return analyzers;
|
||||
}
|
||||
|
||||
public void testParseTextFieldCheckSearchAnalyzerAnalysisMode() {
|
||||
TextFieldMapper.Builder builder = new TextFieldMapper.Builder("textField");
|
||||
for (String settingToTest : new String[] { "search_analyzer", "search_quote_analyzer" }) {
|
||||
|
@ -92,25 +101,23 @@ public class TypeParsersTests extends ESTestCase {
|
|||
Mapper.TypeParser.ParserContext parserContext = mock(Mapper.TypeParser.ParserContext.class);
|
||||
|
||||
// check AnalysisMode.ALL and AnalysisMode.SEARCH_TIME works
|
||||
Map<String, NamedAnalyzer> analyzers = new HashMap<>();
|
||||
Map<String, NamedAnalyzer> analyzers = defaultAnalyzers();
|
||||
AnalysisMode mode = randomFrom(AnalysisMode.ALL, AnalysisMode.SEARCH_TIME);
|
||||
analyzers.put("my_analyzer",
|
||||
new NamedAnalyzer("my_named_analyzer", AnalyzerScope.INDEX, createAnalyzerWithMode("my_analyzer", mode)));
|
||||
analyzers.put("standard", new NamedAnalyzer("standard", AnalyzerScope.INDEX, new StandardAnalyzer()));
|
||||
|
||||
IndexAnalyzers indexAnalyzers = new IndexAnalyzers(indexSettings, new NamedAnalyzer("default", AnalyzerScope.INDEX, null), null,
|
||||
null, analyzers, Collections.emptyMap(), Collections.emptyMap());
|
||||
IndexAnalyzers indexAnalyzers = new IndexAnalyzers(indexSettings, analyzers, Collections.emptyMap(), Collections.emptyMap());
|
||||
when(parserContext.getIndexAnalyzers()).thenReturn(indexAnalyzers);
|
||||
TypeParsers.parseTextField(builder, "name", new HashMap<>(fieldNode), parserContext);
|
||||
|
||||
// check that "analyzer" set to AnalysisMode.INDEX_TIME is blocked
|
||||
mode = AnalysisMode.INDEX_TIME;
|
||||
analyzers = new HashMap<>();
|
||||
analyzers = defaultAnalyzers();
|
||||
analyzers.put("my_analyzer",
|
||||
new NamedAnalyzer("my_named_analyzer", AnalyzerScope.INDEX, createAnalyzerWithMode("my_analyzer", mode)));
|
||||
analyzers.put("standard", new NamedAnalyzer("standard", AnalyzerScope.INDEX, new StandardAnalyzer()));
|
||||
indexAnalyzers = new IndexAnalyzers(indexSettings, new NamedAnalyzer("default", AnalyzerScope.INDEX, null), null, null,
|
||||
analyzers, Collections.emptyMap(), Collections.emptyMap());
|
||||
indexAnalyzers = new IndexAnalyzers(indexSettings, analyzers, Collections.emptyMap(), Collections.emptyMap());
|
||||
when(parserContext.getIndexAnalyzers()).thenReturn(indexAnalyzers);
|
||||
MapperException ex = expectThrows(MapperException.class,
|
||||
() -> TypeParsers.parseTextField(builder, "name", new HashMap<>(fieldNode), parserContext));
|
||||
|
@ -127,11 +134,10 @@ public class TypeParsersTests extends ESTestCase {
|
|||
|
||||
// check that "analyzer" set to AnalysisMode.INDEX_TIME is blocked if there is no search analyzer
|
||||
AnalysisMode mode = AnalysisMode.INDEX_TIME;
|
||||
Map<String, NamedAnalyzer> analyzers = new HashMap<>();
|
||||
Map<String, NamedAnalyzer> analyzers = defaultAnalyzers();
|
||||
analyzers.put("my_analyzer",
|
||||
new NamedAnalyzer("my_named_analyzer", AnalyzerScope.INDEX, createAnalyzerWithMode("my_analyzer", mode)));
|
||||
IndexAnalyzers indexAnalyzers = new IndexAnalyzers(indexSettings, new NamedAnalyzer("default", AnalyzerScope.INDEX, null), null,
|
||||
null, analyzers, Collections.emptyMap(), Collections.emptyMap());
|
||||
IndexAnalyzers indexAnalyzers = new IndexAnalyzers(indexSettings, analyzers, Collections.emptyMap(), Collections.emptyMap());
|
||||
when(parserContext.getIndexAnalyzers()).thenReturn(indexAnalyzers);
|
||||
MapperException ex = expectThrows(MapperException.class,
|
||||
() -> TypeParsers.parseTextField(builder, "name", new HashMap<>(fieldNode), parserContext));
|
||||
|
@ -140,14 +146,13 @@ public class TypeParsersTests extends ESTestCase {
|
|||
|
||||
// check AnalysisMode.INDEX_TIME is okay if search analyzer is also set
|
||||
fieldNode.put("search_analyzer", "standard");
|
||||
analyzers = new HashMap<>();
|
||||
analyzers = defaultAnalyzers();
|
||||
mode = randomFrom(AnalysisMode.ALL, AnalysisMode.INDEX_TIME);
|
||||
analyzers.put("my_analyzer",
|
||||
new NamedAnalyzer("my_named_analyzer", AnalyzerScope.INDEX, createAnalyzerWithMode("my_analyzer", mode)));
|
||||
analyzers.put("standard", new NamedAnalyzer("standard", AnalyzerScope.INDEX, new StandardAnalyzer()));
|
||||
|
||||
indexAnalyzers = new IndexAnalyzers(indexSettings, new NamedAnalyzer("default", AnalyzerScope.INDEX, null), null, null, analyzers,
|
||||
Collections.emptyMap(), Collections.emptyMap());
|
||||
indexAnalyzers = new IndexAnalyzers(indexSettings, analyzers, Collections.emptyMap(), Collections.emptyMap());
|
||||
when(parserContext.getIndexAnalyzers()).thenReturn(indexAnalyzers);
|
||||
TypeParsers.parseTextField(builder, "name", new HashMap<>(fieldNode), parserContext);
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.apache.lucene.analysis.standard.StandardAnalyzer;
|
|||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.index.IndexSettings;
|
||||
import org.elasticsearch.index.analysis.AnalysisRegistry;
|
||||
import org.elasticsearch.index.analysis.AnalyzerScope;
|
||||
import org.elasticsearch.index.analysis.IndexAnalyzers;
|
||||
import org.elasticsearch.index.analysis.NamedAnalyzer;
|
||||
|
@ -60,9 +61,9 @@ public class TranslogHandler implements Engine.TranslogRecoveryRunner {
|
|||
}
|
||||
|
||||
public TranslogHandler(NamedXContentRegistry xContentRegistry, IndexSettings indexSettings) {
|
||||
NamedAnalyzer defaultAnalyzer = new NamedAnalyzer("default", AnalyzerScope.INDEX, new StandardAnalyzer());
|
||||
IndexAnalyzers indexAnalyzers =
|
||||
new IndexAnalyzers(indexSettings, defaultAnalyzer, defaultAnalyzer, defaultAnalyzer, emptyMap(), emptyMap(), emptyMap());
|
||||
Map<String, NamedAnalyzer> analyzers = new HashMap<>();
|
||||
analyzers.put(AnalysisRegistry.DEFAULT_ANALYZER_NAME, new NamedAnalyzer("default", AnalyzerScope.INDEX, new StandardAnalyzer()));
|
||||
IndexAnalyzers indexAnalyzers = new IndexAnalyzers(indexSettings, analyzers, emptyMap(), emptyMap());
|
||||
SimilarityService similarityService = new SimilarityService(indexSettings, null, emptyMap());
|
||||
MapperRegistry mapperRegistry = new IndicesModule(emptyList()).getMapperRegistry();
|
||||
mapperService = new MapperService(indexSettings, indexAnalyzers, xContentRegistry, similarityService, mapperRegistry,
|
||||
|
|
Loading…
Reference in New Issue