diff --git a/src/main/java/org/elasticsearch/common/lucene/uid/UidField.java b/src/main/java/org/elasticsearch/common/lucene/uid/UidField.java index 8b7f8270c71..ab0194ae29d 100644 --- a/src/main/java/org/elasticsearch/common/lucene/uid/UidField.java +++ b/src/main/java/org/elasticsearch/common/lucene/uid/UidField.java @@ -120,6 +120,10 @@ public class UidField extends Field { private long version; + public UidField(String uid) { + this(UidFieldMapper.NAME, uid, 0); + } + public UidField(String name, String uid, long version) { super(name, UidFieldMapper.Defaults.UID_FIELD_TYPE); this.uid = uid; diff --git a/src/main/java/org/elasticsearch/index/codec/postingsformat/BloomFilterPostingsFormatProvider.java b/src/main/java/org/elasticsearch/index/codec/postingsformat/BloomFilterPostingsFormatProvider.java index 07d84052e0c..3ddf2514a7e 100644 --- a/src/main/java/org/elasticsearch/index/codec/postingsformat/BloomFilterPostingsFormatProvider.java +++ b/src/main/java/org/elasticsearch/index/codec/postingsformat/BloomFilterPostingsFormatProvider.java @@ -37,6 +37,11 @@ import java.util.Map; */ public class BloomFilterPostingsFormatProvider extends AbstractPostingsFormatProvider { + public static final class Defaults { + public static final float MAX_SATURATION = 0.1f; + public static final float SATURATION_LIMIT = 0.9f; + } + private final float desiredMaxSaturation; private final float saturationLimit; private final PostingsFormatProvider delegate; @@ -45,8 +50,8 @@ public class BloomFilterPostingsFormatProvider extends AbstractPostingsFormatPro @Inject public BloomFilterPostingsFormatProvider(@IndexSettings Settings indexSettings, @Nullable Map postingFormatFactories, @Assisted String name, @Assisted Settings postingsFormatSettings) { super(name); - this.desiredMaxSaturation = postingsFormatSettings.getAsFloat("desired_max_saturation", 0.1f); - this.saturationLimit = postingsFormatSettings.getAsFloat("saturation_limit", 0.9f); + this.desiredMaxSaturation = postingsFormatSettings.getAsFloat("desired_max_saturation", Defaults.MAX_SATURATION); + this.saturationLimit = postingsFormatSettings.getAsFloat("saturation_limit", Defaults.SATURATION_LIMIT); this.delegate = Helper.lookup(indexSettings, postingsFormatSettings.get("delegate"), postingFormatFactories); this.postingsFormat = new BloomFilteringPostingsFormat( delegate.get(), @@ -71,11 +76,15 @@ public class BloomFilterPostingsFormatProvider extends AbstractPostingsFormatPro return postingsFormat; } - static class CustomBloomFilterFactory extends BloomFilterFactory { + public static class CustomBloomFilterFactory extends BloomFilterFactory { private final float desiredMaxSaturation; private final float saturationLimit; + public CustomBloomFilterFactory() { + this(Defaults.MAX_SATURATION, Defaults.SATURATION_LIMIT); + } + CustomBloomFilterFactory(float desiredMaxSaturation, float saturationLimit) { this.desiredMaxSaturation = desiredMaxSaturation; this.saturationLimit = saturationLimit; diff --git a/src/main/java/org/elasticsearch/index/codec/postingsformat/PostingFormats.java b/src/main/java/org/elasticsearch/index/codec/postingsformat/PostingFormats.java index 0ae8d5200f8..fa980314826 100644 --- a/src/main/java/org/elasticsearch/index/codec/postingsformat/PostingFormats.java +++ b/src/main/java/org/elasticsearch/index/codec/postingsformat/PostingFormats.java @@ -45,9 +45,9 @@ public class PostingFormats { buildInPostingFormatsX.put("memory", new PreBuiltPostingsFormatProvider.Factory("memory", new MemoryPostingsFormat())); // LUCENE UPGRADE: Need to change this to the relevant ones on a lucene upgrade buildInPostingFormatsX.put("pulsing", new PreBuiltPostingsFormatProvider.Factory("pulsing", new Pulsing40PostingsFormat())); - buildInPostingFormatsX.put("bloom_pulsing", new PreBuiltPostingsFormatProvider.Factory("bloom_pulsing", new BloomFilteringPostingsFormat(new Pulsing40PostingsFormat()))); + buildInPostingFormatsX.put("bloom_pulsing", new PreBuiltPostingsFormatProvider.Factory("bloom_pulsing", new BloomFilteringPostingsFormat(new Pulsing40PostingsFormat(), new BloomFilterPostingsFormatProvider.CustomBloomFilterFactory()))); buildInPostingFormatsX.put("default", new PreBuiltPostingsFormatProvider.Factory("default", new Lucene40PostingsFormat())); - buildInPostingFormatsX.put("bloom_default", new PreBuiltPostingsFormatProvider.Factory("bloom_default", new BloomFilteringPostingsFormat(new Lucene40PostingsFormat()))); + buildInPostingFormatsX.put("bloom_default", new PreBuiltPostingsFormatProvider.Factory("bloom_default", new BloomFilteringPostingsFormat(new Lucene40PostingsFormat(), new BloomFilterPostingsFormatProvider.CustomBloomFilterFactory()))); builtInPostingFormats = buildInPostingFormatsX.immutableMap(); } diff --git a/src/main/java/org/elasticsearch/index/engine/Engine.java b/src/main/java/org/elasticsearch/index/engine/Engine.java index 02c59758c12..2020ab5b644 100644 --- a/src/main/java/org/elasticsearch/index/engine/Engine.java +++ b/src/main/java/org/elasticsearch/index/engine/Engine.java @@ -38,7 +38,6 @@ import org.elasticsearch.index.VersionType; import org.elasticsearch.index.deletionpolicy.SnapshotIndexCommit; import org.elasticsearch.index.mapper.DocumentMapper; import org.elasticsearch.index.mapper.ParsedDocument; -import org.elasticsearch.index.mapper.internal.UidFieldMapper; import org.elasticsearch.index.shard.IndexShardComponent; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.translog.Translog; @@ -475,7 +474,7 @@ public interface Engine extends IndexShardComponent, CloseableComponent { } public UidField uidField() { - return (UidField) doc.rootDoc().getField(UidFieldMapper.NAME); + return doc.uid(); } @@ -603,7 +602,7 @@ public interface Engine extends IndexShardComponent, CloseableComponent { } public UidField uidField() { - return (UidField) doc.rootDoc().getField(UidFieldMapper.NAME); + return doc.uid(); } public Index startTime(long startTime) { diff --git a/src/main/java/org/elasticsearch/index/mapper/ParseContext.java b/src/main/java/org/elasticsearch/index/mapper/ParseContext.java index af85557a631..56696016918 100644 --- a/src/main/java/org/elasticsearch/index/mapper/ParseContext.java +++ b/src/main/java/org/elasticsearch/index/mapper/ParseContext.java @@ -24,6 +24,7 @@ import org.apache.lucene.document.Document; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.lucene.all.AllEntries; +import org.elasticsearch.common.lucene.uid.UidField; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.analysis.AnalysisService; @@ -65,7 +66,7 @@ public class ParseContext { private DocumentMapper.ParseListener listener; - private String uid; + private UidField uid; private StringBuilder stringBuilder = new StringBuilder(); @@ -218,14 +219,14 @@ public class ParseContext { this.id = id; } - public String uid() { + public UidField uid() { return this.uid; } /** * Really, just the uid mapper should set this. */ - public void uid(String uid) { + public void uid(UidField uid) { this.uid = uid; } diff --git a/src/main/java/org/elasticsearch/index/mapper/ParsedDocument.java b/src/main/java/org/elasticsearch/index/mapper/ParsedDocument.java index 8140835e34a..0f52e7f8d4f 100644 --- a/src/main/java/org/elasticsearch/index/mapper/ParsedDocument.java +++ b/src/main/java/org/elasticsearch/index/mapper/ParsedDocument.java @@ -22,6 +22,7 @@ package org.elasticsearch.index.mapper; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.document.Document; import org.elasticsearch.common.bytes.BytesReference; +import org.elasticsearch.common.lucene.uid.UidField; import java.util.Arrays; import java.util.List; @@ -31,7 +32,7 @@ import java.util.List; */ public class ParsedDocument { - private final String uid; + private final UidField uid; private final String id; @@ -54,10 +55,10 @@ public class ParsedDocument { private String parent; public ParsedDocument(String uid, String id, String type, String routing, long timestamp, long ttl, Document document, Analyzer analyzer, BytesReference source, boolean mappingsModified) { - this(uid, id, type, routing, timestamp, ttl, Arrays.asList(document), analyzer, source, mappingsModified); + this(new UidField(uid), id, type, routing, timestamp, ttl, Arrays.asList(document), analyzer, source, mappingsModified); } - public ParsedDocument(String uid, String id, String type, String routing, long timestamp, long ttl, List documents, Analyzer analyzer, BytesReference source, boolean mappingsModified) { + public ParsedDocument(UidField uid, String id, String type, String routing, long timestamp, long ttl, List documents, Analyzer analyzer, BytesReference source, boolean mappingsModified) { this.uid = uid; this.id = id; this.type = type; @@ -70,7 +71,7 @@ public class ParsedDocument { this.mappingsModified = mappingsModified; } - public String uid() { + public UidField uid() { return this.uid; } diff --git a/src/main/java/org/elasticsearch/index/mapper/internal/UidFieldMapper.java b/src/main/java/org/elasticsearch/index/mapper/internal/UidFieldMapper.java index 62adcbb0ce6..95e4e625a88 100644 --- a/src/main/java/org/elasticsearch/index/mapper/internal/UidFieldMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/internal/UidFieldMapper.java @@ -165,12 +165,12 @@ public class UidFieldMapper extends AbstractFieldMapper implements Internal @Override protected Field parseCreateField(ParseContext context) throws IOException { - context.uid(Uid.createUid(context.stringBuilder(), context.type(), context.id())); // so, caching uid stream and field is fine // since we don't do any mapping parsing without immediate indexing // and, when percolating, we don't index the uid UidField field = fieldCache.get(); - field.setUid(context.uid()); + field.setUid(Uid.createUid(context.stringBuilder(), context.type(), context.id())); + context.uid(field); return field; // version get updated by the engine } diff --git a/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java b/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java index 3464798bf13..1bdeff116c9 100644 --- a/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java +++ b/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java @@ -295,7 +295,7 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I long startTime = System.nanoTime(); DocumentMapper docMapper = mapperService.documentMapperWithAutoCreate(source.type()); ParsedDocument doc = docMapper.parse(source); - return new Engine.Create(docMapper, docMapper.uidMapper().term(doc.uid()), doc).startTime(startTime); + return new Engine.Create(docMapper, docMapper.uidMapper().term(doc.uid().uid()), doc).startTime(startTime); } @Override @@ -316,7 +316,7 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I long startTime = System.nanoTime(); DocumentMapper docMapper = mapperService.documentMapperWithAutoCreate(source.type()); ParsedDocument doc = docMapper.parse(source); - return new Engine.Index(docMapper, docMapper.uidMapper().term(doc.uid()), doc).startTime(startTime); + return new Engine.Index(docMapper, docMapper.uidMapper().term(doc.uid().uid()), doc).startTime(startTime); } @Override @@ -371,7 +371,7 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I query = filterQueryIfNeeded(query, types); Filter aliasFilter = indexAliasesService.aliasFilter(filteringAliases); - Filter parentFilter = mapperService.hasNested() ? indexCache.filter().cache(NonNestedDocsFilter.INSTANCE) : null; + Filter parentFilter = mapperService.hasNested() ? indexCache.filter().cache(NonNestedDocsFilter.INSTANCE) : null; return new Engine.DeleteByQuery(query, querySource, filteringAliases, aliasFilter, parentFilter, types).startTime(startTime); }