|
@@ -20,13 +20,11 @@
|
|
|
package org.elasticsearch.index.mapper;
|
|
|
|
|
|
import com.carrotsearch.hppc.ObjectOpenHashSet;
|
|
|
-import com.google.common.base.Charsets;
|
|
|
import com.google.common.base.Predicate;
|
|
|
import com.google.common.collect.ImmutableList;
|
|
|
import com.google.common.collect.ImmutableMap;
|
|
|
import com.google.common.collect.Iterators;
|
|
|
import com.google.common.collect.Lists;
|
|
|
-
|
|
|
import org.apache.lucene.analysis.Analyzer;
|
|
|
import org.apache.lucene.analysis.DelegatingAnalyzerWrapper;
|
|
|
import org.apache.lucene.index.IndexOptions;
|
|
@@ -44,14 +42,9 @@ import org.elasticsearch.common.collect.ImmutableOpenMap;
|
|
|
import org.elasticsearch.common.collect.Tuple;
|
|
|
import org.elasticsearch.common.compress.CompressedString;
|
|
|
import org.elasticsearch.common.inject.Inject;
|
|
|
-import org.elasticsearch.common.io.FileSystemUtils;
|
|
|
-import org.elasticsearch.common.io.PathUtils;
|
|
|
-import org.elasticsearch.common.io.Streams;
|
|
|
import org.elasticsearch.common.lucene.search.Queries;
|
|
|
import org.elasticsearch.common.regex.Regex;
|
|
|
import org.elasticsearch.common.settings.Settings;
|
|
|
-import org.elasticsearch.env.Environment;
|
|
|
-import org.elasticsearch.env.FailedToResolveConfigException;
|
|
|
import org.elasticsearch.index.AbstractIndexComponent;
|
|
|
import org.elasticsearch.index.Index;
|
|
|
import org.elasticsearch.index.analysis.AnalysisService;
|
|
@@ -67,8 +60,6 @@ import org.elasticsearch.percolator.PercolatorService;
|
|
|
import org.elasticsearch.script.ScriptService;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
-import java.net.MalformedURLException;
|
|
|
-import java.net.URL;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Collection;
|
|
|
import java.util.Collections;
|
|
@@ -122,7 +113,7 @@ public class MapperService extends AbstractIndexComponent {
|
|
|
private volatile ImmutableMap<String, FieldMapper<?>> unmappedFieldMappers = ImmutableMap.of();
|
|
|
|
|
|
@Inject
|
|
|
- public MapperService(Index index, @IndexSettings Settings indexSettings, Environment environment, AnalysisService analysisService, IndexFieldDataService fieldDataService,
|
|
|
+ public MapperService(Index index, @IndexSettings Settings indexSettings, AnalysisService analysisService, IndexFieldDataService fieldDataService,
|
|
|
SimilarityLookupService similarityLookupService,
|
|
|
ScriptService scriptService) {
|
|
|
super(index, indexSettings);
|
|
@@ -134,105 +125,34 @@ public class MapperService extends AbstractIndexComponent {
|
|
|
this.searchQuoteAnalyzer = new SmartIndexNameSearchQuoteAnalyzer(analysisService.defaultSearchQuoteAnalyzer());
|
|
|
|
|
|
this.dynamic = indexSettings.getAsBoolean("index.mapper.dynamic", true);
|
|
|
- String defaultMappingLocation = indexSettings.get("index.mapper.default_mapping_location");
|
|
|
- final URL defaultMappingUrl;
|
|
|
+ defaultPercolatorMappingSource = "{\n" +
|
|
|
+ "\"_default_\":{\n" +
|
|
|
+ "\"properties\" : {\n" +
|
|
|
+ "\"query\" : {\n" +
|
|
|
+ "\"type\" : \"object\",\n" +
|
|
|
+ "\"enabled\" : false\n" +
|
|
|
+ "}\n" +
|
|
|
+ "}\n" +
|
|
|
+ "}\n" +
|
|
|
+ "}";
|
|
|
if (index.getName().equals(ScriptService.SCRIPT_INDEX)){
|
|
|
- defaultMappingUrl = getMappingUrl(indexSettings, environment, defaultMappingLocation, "script-mapping.json", "org/elasticsearch/index/mapper/script-mapping.json");
|
|
|
- } else {
|
|
|
- defaultMappingUrl = getMappingUrl(indexSettings, environment, defaultMappingLocation, "default-mapping.json", "org/elasticsearch/index/mapper/default-mapping.json");
|
|
|
- }
|
|
|
-
|
|
|
- if (defaultMappingUrl == null) {
|
|
|
- logger.info("failed to find default-mapping.json in the classpath, using the default template");
|
|
|
- if (index.getName().equals(ScriptService.SCRIPT_INDEX)){
|
|
|
- defaultMappingSource = "{" +
|
|
|
- "\"_default_\": {" +
|
|
|
- "\"properties\": {" +
|
|
|
+ defaultMappingSource = "{" +
|
|
|
+ "\"_default_\": {" +
|
|
|
+ "\"properties\": {" +
|
|
|
"\"script\": { \"enabled\": false }," +
|
|
|
"\"template\": { \"enabled\": false }" +
|
|
|
- "}" +
|
|
|
- "}" +
|
|
|
- "}";
|
|
|
- } else {
|
|
|
- defaultMappingSource = "{\n" +
|
|
|
- " \"_default_\":{\n" +
|
|
|
- " }\n" +
|
|
|
- "}";
|
|
|
- }
|
|
|
+ "}" +
|
|
|
+ "}" +
|
|
|
+ "}";
|
|
|
} else {
|
|
|
- try {
|
|
|
- defaultMappingSource = Streams.copyToString(FileSystemUtils.newBufferedReader(defaultMappingUrl, Charsets.UTF_8));
|
|
|
- } catch (IOException e) {
|
|
|
- throw new MapperException("Failed to load default mapping source from [" + defaultMappingLocation + "]", e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- String percolatorMappingLocation = indexSettings.get("index.mapper.default_percolator_mapping_location");
|
|
|
- URL percolatorMappingUrl = null;
|
|
|
- if (percolatorMappingLocation != null) {
|
|
|
- try {
|
|
|
- percolatorMappingUrl = environment.resolveConfig(percolatorMappingLocation);
|
|
|
- } catch (FailedToResolveConfigException e) {
|
|
|
- // not there, default to the built in one
|
|
|
- try {
|
|
|
- percolatorMappingUrl = PathUtils.get(percolatorMappingLocation).toUri().toURL();
|
|
|
- } catch (MalformedURLException e1) {
|
|
|
- throw new FailedToResolveConfigException("Failed to resolve default percolator mapping location [" + percolatorMappingLocation + "]");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if (percolatorMappingUrl != null) {
|
|
|
- try {
|
|
|
- defaultPercolatorMappingSource = Streams.copyToString(FileSystemUtils.newBufferedReader(percolatorMappingUrl, Charsets.UTF_8));
|
|
|
- } catch (IOException e) {
|
|
|
- throw new MapperException("Failed to load default percolator mapping source from [" + percolatorMappingUrl + "]", e);
|
|
|
- }
|
|
|
- } else {
|
|
|
- defaultPercolatorMappingSource = "{\n" +
|
|
|
- //" \"" + PercolatorService.TYPE_NAME + "\":{\n" +
|
|
|
- " \"" + "_default_" + "\":{\n" +
|
|
|
- " \"properties\" : {\n" +
|
|
|
- " \"query\" : {\n" +
|
|
|
- " \"type\" : \"object\",\n" +
|
|
|
- " \"enabled\" : false\n" +
|
|
|
- " }\n" +
|
|
|
- " }\n" +
|
|
|
- " }\n" +
|
|
|
- "}";
|
|
|
+ defaultMappingSource = "{\"_default_\":{}}";
|
|
|
}
|
|
|
|
|
|
if (logger.isTraceEnabled()) {
|
|
|
- logger.trace("using dynamic[{}], default mapping: default_mapping_location[{}], loaded_from[{}] and source[{}], default percolator mapping: location[{}], loaded_from[{}] and source[{}]", dynamic, defaultMappingLocation, defaultMappingUrl, defaultMappingSource, percolatorMappingLocation, percolatorMappingUrl, defaultPercolatorMappingSource);
|
|
|
+ logger.trace("using dynamic[{}], default mapping source[{}], default percolator mapping source[{}]", dynamic, defaultMappingSource, defaultPercolatorMappingSource);
|
|
|
} else if (logger.isDebugEnabled()) {
|
|
|
- logger.debug("using dynamic[{}], default mapping: default_mapping_location[{}], loaded_from[{}], default percolator mapping: location[{}], loaded_from[{}]", dynamic, defaultMappingLocation, defaultMappingUrl, percolatorMappingLocation, percolatorMappingUrl);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private URL getMappingUrl(Settings indexSettings, Environment environment, String mappingLocation, String configString, String resourceLocation) {
|
|
|
- URL mappingUrl;
|
|
|
- if (mappingLocation == null) {
|
|
|
- try {
|
|
|
- mappingUrl = environment.resolveConfig(configString);
|
|
|
- } catch (FailedToResolveConfigException e) {
|
|
|
- // not there, default to the built in one
|
|
|
- mappingUrl = indexSettings.getClassLoader().getResource(resourceLocation);
|
|
|
- if (mappingUrl == null) {
|
|
|
- mappingUrl = MapperService.class.getClassLoader().getResource(resourceLocation);
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- try {
|
|
|
- mappingUrl = environment.resolveConfig(mappingLocation);
|
|
|
- } catch (FailedToResolveConfigException e) {
|
|
|
- // not there, default to the built in one
|
|
|
- try {
|
|
|
- mappingUrl = PathUtils.get(mappingLocation).toUri().toURL();
|
|
|
- } catch (MalformedURLException e1) {
|
|
|
- throw new FailedToResolveConfigException("Failed to resolve dynamic mapping location [" + mappingLocation + "]");
|
|
|
- }
|
|
|
- }
|
|
|
+ logger.debug("using dynamic[{}]", dynamic);
|
|
|
}
|
|
|
- return mappingUrl;
|
|
|
}
|
|
|
|
|
|
public void close() {
|