Mappings: Remove file based default mappings
Using files that must be specified on each node is an anti-pattern from the API based goal of ES. This change removes the ability to specify the default mapping with a file on each node. closes #10620
This commit is contained in:
parent
a0451a37cc
commit
4ef9f3ca63
|
@ -32,7 +32,7 @@ mapping specified in the <<indices-create-index,`create-index`>> or
|
||||||
`_default_` mapping.
|
`_default_` mapping.
|
||||||
|
|
||||||
The default mapping definition is a plain mapping definition that is
|
The default mapping definition is a plain mapping definition that is
|
||||||
embedded within ElasticSearch:
|
embedded within Elasticsearch:
|
||||||
|
|
||||||
[source,js]
|
[source,js]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
@ -46,11 +46,8 @@ Pretty short, isn't it? Basically, everything is `_default_`ed, including the
|
||||||
dynamic nature of the root object mapping which allows new fields to be added
|
dynamic nature of the root object mapping which allows new fields to be added
|
||||||
automatically.
|
automatically.
|
||||||
|
|
||||||
The built-in default mapping definition can be overridden in several ways. A
|
The default mapping can be overridden by specifying the `_default_` type when
|
||||||
`_default_` mapping can be specified when creating a new index, or the global
|
creating a new index.
|
||||||
`_default_` mapping (for all indices) can be configured by creating a file
|
|
||||||
called `config/default-mapping.json`. (This location can be changed with
|
|
||||||
the `index.mapper.default_mapping_location` setting.)
|
|
||||||
|
|
||||||
Dynamic creation of mappings for unmapped types can be completely
|
Dynamic creation of mappings for unmapped types can be completely
|
||||||
disabled by setting `index.mapper.dynamic` to `false`.
|
disabled by setting `index.mapper.dynamic` to `false`.
|
||||||
|
|
|
@ -71,8 +71,6 @@ include::mapping/date-format.asciidoc[]
|
||||||
|
|
||||||
include::mapping/dynamic-mapping.asciidoc[]
|
include::mapping/dynamic-mapping.asciidoc[]
|
||||||
|
|
||||||
include::mapping/conf-mappings.asciidoc[]
|
|
||||||
|
|
||||||
include::mapping/meta.asciidoc[]
|
include::mapping/meta.asciidoc[]
|
||||||
|
|
||||||
include::mapping/transform.asciidoc[]
|
include::mapping/transform.asciidoc[]
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
[[mapping-conf-mappings]]
|
|
||||||
== Config Mappings
|
|
||||||
|
|
||||||
Creating new mappings can be done using the
|
|
||||||
<<indices-put-mapping,Put Mapping>>
|
|
||||||
API. When a document is indexed with no mapping associated with it in
|
|
||||||
the specific index, the
|
|
||||||
<<mapping-dynamic-mapping,dynamic / default
|
|
||||||
mapping>> feature will kick in and automatically create mapping
|
|
||||||
definition for it.
|
|
||||||
|
|
||||||
Mappings can also be provided on the node level, meaning that each index
|
|
||||||
created will automatically be started with all the mappings defined
|
|
||||||
within a certain location.
|
|
||||||
|
|
||||||
Mappings can be defined within files called `[mapping_name].json` and be
|
|
||||||
placed either under `config/mappings/_default` location, or under
|
|
||||||
`config/mappings/[index_name]` (for mappings that should be associated
|
|
||||||
only with a specific index).
|
|
|
@ -21,12 +21,8 @@ embedded within the distribution:
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
|
||||||
Pretty short, isn't it? Basically, everything is defaulted, especially the
|
Pretty short, isn't it? Basically, everything is defaulted, especially the
|
||||||
dynamic nature of the root object mapping. The default mapping
|
dynamic nature of the root object mapping. The default mapping can be
|
||||||
definition can be overridden in several manners. The simplest manner is
|
overridden by specifying the `_default_` type when creating a new index.
|
||||||
to simply define a file called `default-mapping.json` and to place it
|
|
||||||
under the `config` directory (which can be configured to exist in a
|
|
||||||
different location). It can also be explicitly set using the
|
|
||||||
`index.mapper.default_mapping_location` setting.
|
|
||||||
|
|
||||||
The dynamic creation of mappings for unmapped types can be completely
|
The dynamic creation of mappings for unmapped types can be completely
|
||||||
disabled by setting `index.mapper.dynamic` to `false`.
|
disabled by setting `index.mapper.dynamic` to `false`.
|
||||||
|
|
|
@ -312,6 +312,14 @@ They are always stored with doc values, and not indexed.
|
||||||
The `_source` field no longer supports `includes` and `excludes` paramters. When
|
The `_source` field no longer supports `includes` and `excludes` paramters. When
|
||||||
`_source` is enabled, the entire original source will be stored.
|
`_source` is enabled, the entire original source will be stored.
|
||||||
|
|
||||||
|
==== Config based mappings
|
||||||
|
The ability to specify mappings in configuration files has been removed. To specify
|
||||||
|
default mappings that apply to multiple indexes, use index templates.
|
||||||
|
|
||||||
|
The following settings are no longer valid:
|
||||||
|
* `index.mapper.default_mapping_location`
|
||||||
|
* `index.mapper.default_percolator_mapping_location`
|
||||||
|
|
||||||
=== Codecs
|
=== Codecs
|
||||||
|
|
||||||
It is no longer possible to specify per-field postings and doc values formats
|
It is no longer possible to specify per-field postings and doc values formats
|
||||||
|
|
|
@ -20,13 +20,11 @@
|
||||||
package org.elasticsearch.index.mapper;
|
package org.elasticsearch.index.mapper;
|
||||||
|
|
||||||
import com.carrotsearch.hppc.ObjectOpenHashSet;
|
import com.carrotsearch.hppc.ObjectOpenHashSet;
|
||||||
import com.google.common.base.Charsets;
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.Iterators;
|
import com.google.common.collect.Iterators;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
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.apache.lucene.index.IndexOptions;
|
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.collect.Tuple;
|
||||||
import org.elasticsearch.common.compress.CompressedString;
|
import org.elasticsearch.common.compress.CompressedString;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
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.lucene.search.Queries;
|
||||||
import org.elasticsearch.common.regex.Regex;
|
import org.elasticsearch.common.regex.Regex;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
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.AbstractIndexComponent;
|
||||||
import org.elasticsearch.index.Index;
|
import org.elasticsearch.index.Index;
|
||||||
import org.elasticsearch.index.analysis.AnalysisService;
|
import org.elasticsearch.index.analysis.AnalysisService;
|
||||||
|
@ -67,8 +60,6 @@ import org.elasticsearch.percolator.PercolatorService;
|
||||||
import org.elasticsearch.script.ScriptService;
|
import org.elasticsearch.script.ScriptService;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -122,7 +113,7 @@ public class MapperService extends AbstractIndexComponent {
|
||||||
private volatile ImmutableMap<String, FieldMapper<?>> unmappedFieldMappers = ImmutableMap.of();
|
private volatile ImmutableMap<String, FieldMapper<?>> unmappedFieldMappers = ImmutableMap.of();
|
||||||
|
|
||||||
@Inject
|
@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,
|
SimilarityLookupService similarityLookupService,
|
||||||
ScriptService scriptService) {
|
ScriptService scriptService) {
|
||||||
super(index, indexSettings);
|
super(index, indexSettings);
|
||||||
|
@ -134,107 +125,36 @@ public class MapperService extends AbstractIndexComponent {
|
||||||
this.searchQuoteAnalyzer = new SmartIndexNameSearchQuoteAnalyzer(analysisService.defaultSearchQuoteAnalyzer());
|
this.searchQuoteAnalyzer = new SmartIndexNameSearchQuoteAnalyzer(analysisService.defaultSearchQuoteAnalyzer());
|
||||||
|
|
||||||
this.dynamic = indexSettings.getAsBoolean("index.mapper.dynamic", true);
|
this.dynamic = indexSettings.getAsBoolean("index.mapper.dynamic", true);
|
||||||
String defaultMappingLocation = indexSettings.get("index.mapper.default_mapping_location");
|
defaultPercolatorMappingSource = "{\n" +
|
||||||
final URL defaultMappingUrl;
|
"\"_default_\":{\n" +
|
||||||
|
"\"properties\" : {\n" +
|
||||||
|
"\"query\" : {\n" +
|
||||||
|
"\"type\" : \"object\",\n" +
|
||||||
|
"\"enabled\" : false\n" +
|
||||||
|
"}\n" +
|
||||||
|
"}\n" +
|
||||||
|
"}\n" +
|
||||||
|
"}";
|
||||||
if (index.getName().equals(ScriptService.SCRIPT_INDEX)){
|
if (index.getName().equals(ScriptService.SCRIPT_INDEX)){
|
||||||
defaultMappingUrl = getMappingUrl(indexSettings, environment, defaultMappingLocation, "script-mapping.json", "org/elasticsearch/index/mapper/script-mapping.json");
|
defaultMappingSource = "{" +
|
||||||
} else {
|
"\"_default_\": {" +
|
||||||
defaultMappingUrl = getMappingUrl(indexSettings, environment, defaultMappingLocation, "default-mapping.json", "org/elasticsearch/index/mapper/default-mapping.json");
|
"\"properties\": {" +
|
||||||
}
|
|
||||||
|
|
||||||
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\": {" +
|
|
||||||
"\"script\": { \"enabled\": false }," +
|
"\"script\": { \"enabled\": false }," +
|
||||||
"\"template\": { \"enabled\": false }" +
|
"\"template\": { \"enabled\": false }" +
|
||||||
"}" +
|
"}" +
|
||||||
"}" +
|
"}" +
|
||||||
"}";
|
"}";
|
||||||
} else {
|
|
||||||
defaultMappingSource = "{\n" +
|
|
||||||
" \"_default_\":{\n" +
|
|
||||||
" }\n" +
|
|
||||||
"}";
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
try {
|
defaultMappingSource = "{\"_default_\":{}}";
|
||||||
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" +
|
|
||||||
"}";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (logger.isTraceEnabled()) {
|
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()) {
|
} 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);
|
logger.debug("using dynamic[{}]", dynamic);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 + "]");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return mappingUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
for (DocumentMapper documentMapper : mappers.values()) {
|
for (DocumentMapper documentMapper : mappers.values()) {
|
||||||
documentMapper.close();
|
documentMapper.close();
|
||||||
|
|
Loading…
Reference in New Issue