Skip to content

Remove the ability to have custom per-field postings and doc values formats. #9741

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions dev-tools/create-bwc-index.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,18 @@ def generate_index(client, version):
'path': 'myrouting'
}
}
mappings['custom_formats'] = {
'properties': {
'string_with_custom_postings': {
'type': 'string',
'postings_format': 'Lucene41'
},
'long_with_custom_doc_values': {
'type': 'long',
'doc_values_format': 'Lucene42'
}
}
}


client.indices.create(index='test', body={
Expand Down
12 changes: 12 additions & 0 deletions docs/reference/migration/migrate_2_0.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,15 @@ curl -XGET 'localhost:9200/index/type/_search'
}
---------------

=== Codecs

It is no longer possible to specify per-field postings and doc values formats
in the mappings. This setting will be ignored on indices created before
elasticsearch 2.0 and will cause mapping parsing to fail on indices created on
or after 2.0. For old indices, this means that new segments will be written
with the default postings and doc values formats of the current codec.

It is still possible to change the whole codec by using the `index.codec`
setting. Please however note that using a non-default codec is discouraged as
it could prevent future versions of Elasticsearch from being able to read the
index.
183 changes: 0 additions & 183 deletions src/main/java/org/elasticsearch/index/codec/CodecModule.java

This file was deleted.

30 changes: 4 additions & 26 deletions src/main/java/org/elasticsearch/index/codec/CodecService.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import org.apache.lucene.codecs.Codec;
import org.apache.lucene.codecs.lucene50.Lucene50Codec;
import org.apache.lucene.codecs.lucene50.Lucene50StoredFieldsFormat;
import org.apache.lucene.codecs.lucene50.Lucene50StoredFieldsFormat.Mode;
import org.elasticsearch.ElasticsearchIllegalArgumentException;
import org.elasticsearch.common.collect.MapBuilder;
Expand All @@ -32,8 +31,6 @@
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.AbstractIndexComponent;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.codec.docvaluesformat.DocValuesFormatService;
import org.elasticsearch.index.codec.postingsformat.PostingsFormatService;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.settings.IndexSettings;

Expand All @@ -48,8 +45,6 @@
*/
public class CodecService extends AbstractIndexComponent {

private final PostingsFormatService postingsFormatService;
private final DocValuesFormatService docValuesFormatService;
private final MapperService mapperService;
private final ImmutableMap<String, Codec> codecs;

Expand All @@ -61,46 +56,29 @@ public CodecService(Index index) {
}

public CodecService(Index index, @IndexSettings Settings indexSettings) {
this(index, indexSettings, new PostingsFormatService(index, indexSettings), new DocValuesFormatService(index, indexSettings), null);
this(index, indexSettings, null);
}

@Inject
public CodecService(Index index, @IndexSettings Settings indexSettings, PostingsFormatService postingsFormatService,
DocValuesFormatService docValuesFormatService, MapperService mapperService) {
public CodecService(Index index, @IndexSettings Settings indexSettings, MapperService mapperService) {
super(index, indexSettings);
this.postingsFormatService = postingsFormatService;
this.docValuesFormatService = docValuesFormatService;
this.mapperService = mapperService;
MapBuilder<String, Codec> codecs = MapBuilder.<String, Codec>newMapBuilder();
if (mapperService == null) {
codecs.put(DEFAULT_CODEC, new Lucene50Codec());
codecs.put(BEST_COMPRESSION_CODEC, new Lucene50Codec(Mode.BEST_COMPRESSION));
} else {
codecs.put(DEFAULT_CODEC,
new PerFieldMappingPostingFormatCodec(Mode.BEST_SPEED,
mapperService,
postingsFormatService.get(PostingsFormatService.DEFAULT_FORMAT).get(),
docValuesFormatService.get(DocValuesFormatService.DEFAULT_FORMAT).get(), logger));
new PerFieldMappingPostingFormatCodec(Mode.BEST_SPEED, mapperService, logger));
codecs.put(BEST_COMPRESSION_CODEC,
new PerFieldMappingPostingFormatCodec(Mode.BEST_COMPRESSION,
mapperService,
postingsFormatService.get(PostingsFormatService.DEFAULT_FORMAT).get(),
docValuesFormatService.get(DocValuesFormatService.DEFAULT_FORMAT).get(), logger));
new PerFieldMappingPostingFormatCodec(Mode.BEST_COMPRESSION, mapperService, logger));
}
for (String codec : Codec.availableCodecs()) {
codecs.put(codec, Codec.forName(codec));
}
this.codecs = codecs.immutableMap();
}

public PostingsFormatService postingsFormatService() {
return this.postingsFormatService;
}

public DocValuesFormatService docValuesFormatService() {
return docValuesFormatService;
}

public MapperService mapperService() {
return mapperService;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,19 @@
package org.elasticsearch.index.codec;

import org.apache.lucene.codecs.Codec;
import org.apache.lucene.codecs.DocValuesFormat;
import org.apache.lucene.codecs.PostingsFormat;
import org.apache.lucene.codecs.lucene50.Lucene50Codec;
import org.apache.lucene.codecs.lucene50.Lucene50StoredFieldsFormat;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.index.codec.docvaluesformat.DocValuesFormatProvider;
import org.elasticsearch.index.codec.postingsformat.PostingsFormatProvider;
import org.elasticsearch.index.mapper.FieldMappers;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.mapper.core.CompletionFieldMapper;
import org.elasticsearch.search.suggest.completion.Completion090PostingsFormat;
import org.elasticsearch.search.suggest.completion.Completion090PostingsFormat.CompletionLookupProvider;

import java.util.HashMap;
import java.util.Map;

/**
* {@link PerFieldMappingPostingFormatCodec This postings format} is the default
Expand All @@ -43,40 +46,29 @@
public class PerFieldMappingPostingFormatCodec extends Lucene50Codec {
private final ESLogger logger;
private final MapperService mapperService;
private final PostingsFormat defaultPostingFormat;
private final DocValuesFormat defaultDocValuesFormat;

static {
assert Codec.forName(Lucene.LATEST_CODEC).getClass().isAssignableFrom(PerFieldMappingPostingFormatCodec.class) : "PerFieldMappingPostingFormatCodec must subclass the latest lucene codec: " + Lucene.LATEST_CODEC;
}

public PerFieldMappingPostingFormatCodec(Lucene50StoredFieldsFormat.Mode compressionMode, MapperService mapperService, PostingsFormat defaultPostingFormat, DocValuesFormat defaultDocValuesFormat, ESLogger logger) {
public PerFieldMappingPostingFormatCodec(Lucene50StoredFieldsFormat.Mode compressionMode, MapperService mapperService, ESLogger logger) {
super(compressionMode);
this.mapperService = mapperService;
this.logger = logger;
this.defaultPostingFormat = defaultPostingFormat;
this.defaultDocValuesFormat = defaultDocValuesFormat;
}

@Override
public PostingsFormat getPostingsFormatForField(String field) {
final FieldMappers indexName = mapperService.indexName(field);
if (indexName == null) {
logger.warn("no index mapper found for field: [{}] returning default postings format", field);
return defaultPostingFormat;
} else if (indexName.mapper() instanceof CompletionFieldMapper) {
// CompletionFieldMapper needs a special postings format
final CompletionFieldMapper mapper = (CompletionFieldMapper) indexName.mapper();
final PostingsFormat defaultFormat = super.getPostingsFormatForField(field);
return mapper.postingsFormat(defaultFormat);
}
PostingsFormatProvider postingsFormat = indexName.mapper().postingsFormatProvider();
return postingsFormat != null ? postingsFormat.get() : defaultPostingFormat;
return super.getPostingsFormatForField(field);
}

@Override
public DocValuesFormat getDocValuesFormatForField(String field) {
final FieldMappers indexName = mapperService.indexName(field);
if (indexName == null) {
logger.warn("no index mapper found for field: [{}] returning default doc values format", field);
return defaultDocValuesFormat;
}
DocValuesFormatProvider docValuesFormat = indexName.mapper().docValuesFormatProvider();
return docValuesFormat != null ? docValuesFormat.get() : defaultDocValuesFormat;
}
}
Loading