move field data type to simply be type and settings
This commit is contained in:
parent
50ac477d92
commit
613b746299
|
@ -360,6 +360,10 @@ public class ImmutableSettings implements Settings {
|
|||
}
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a builder to be used in order to build settings.
|
||||
*/
|
||||
|
|
|
@ -19,42 +19,54 @@
|
|||
|
||||
package org.elasticsearch.index.fielddata;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class FieldDataType {
|
||||
|
||||
private final String type;
|
||||
@Nullable
|
||||
private final String format;
|
||||
private final ImmutableMap<String, String> options;
|
||||
private final Settings settings;
|
||||
|
||||
public FieldDataType(String type) {
|
||||
this(type, null, ImmutableMap.<String, String>of());
|
||||
this(type, ImmutableSettings.Builder.EMPTY_SETTINGS);
|
||||
}
|
||||
|
||||
public FieldDataType(String type, String format) {
|
||||
this(type, format, ImmutableMap.<String, String>of());
|
||||
public FieldDataType(String type, Settings.Builder builder) {
|
||||
this(type, builder.build());
|
||||
}
|
||||
|
||||
public FieldDataType(String type, @Nullable String format, ImmutableMap<String, String> options) {
|
||||
public FieldDataType(String type, Settings settings) {
|
||||
this.type = type;
|
||||
this.format = format;
|
||||
this.options = options;
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getFormat() {
|
||||
return this.format;
|
||||
public Settings getSettings() {
|
||||
return this.settings;
|
||||
}
|
||||
|
||||
public ImmutableMap<String, String> getOptions() {
|
||||
return this.options;
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
FieldDataType that = (FieldDataType) o;
|
||||
|
||||
if (!settings.equals(that.settings)) return false;
|
||||
if (!type.equals(that.type)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = type.hashCode();
|
||||
result = 31 * result + settings.hashCode();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -119,17 +119,11 @@ public class IndexFieldDataService extends AbstractIndexComponent {
|
|||
fieldData = loadedFieldData.get(fieldNames.indexName());
|
||||
if (fieldData == null) {
|
||||
IndexFieldData.Builder builder = null;
|
||||
if (type.getFormat() != null) {
|
||||
builder = buildersByTypeAndFormat.get(Tuple.tuple(type.getType(), type.getFormat()));
|
||||
if (builder == null) {
|
||||
logger.warn("failed to find format [" + type.getFormat() + "] for field [" + fieldNames.fullName() + "], will use default");
|
||||
}
|
||||
}
|
||||
String format = indexSettings.get("index.fielddata.type." + type.getType() + ".format", null);
|
||||
String format = type.getSettings().get("format", indexSettings.get("index.fielddata.type." + type.getType() + ".format", null));
|
||||
if (format != null) {
|
||||
builder = buildersByTypeAndFormat.get(Tuple.tuple(type.getType(), type.getFormat()));
|
||||
builder = buildersByTypeAndFormat.get(Tuple.tuple(type.getType(), format));
|
||||
if (builder == null) {
|
||||
logger.warn("failed to find index level type format [" + format + "] for field [" + fieldNames.fullName() + "], will use default");
|
||||
logger.warn("failed to find format [" + format + "] for field [" + fieldNames.fullName() + "], will use default");
|
||||
}
|
||||
}
|
||||
if (builder == null) {
|
||||
|
@ -140,17 +134,13 @@ public class IndexFieldDataService extends AbstractIndexComponent {
|
|||
}
|
||||
|
||||
IndexFieldDataCache cache;
|
||||
if (type.getOptions().containsKey("cache")) {
|
||||
String cacheType = type.getOptions().get("cache");
|
||||
if ("resident".equals(cacheType)) {
|
||||
cache = new IndexFieldDataCache.Resident();
|
||||
} else if ("soft".equals(cacheType)) {
|
||||
cache = new IndexFieldDataCache.Soft();
|
||||
} else {
|
||||
throw new ElasticSearchIllegalArgumentException("cache type not supported [" + cacheType + "] for field [" + fieldNames.fullName() + "]");
|
||||
}
|
||||
} else {
|
||||
String cacheType = type.getSettings().get("cache", indexSettings.get("index.fielddata.cache", "resident"));
|
||||
if ("resident".equals(cacheType)) {
|
||||
cache = new IndexFieldDataCache.Resident();
|
||||
} else if ("soft".equals(cacheType)) {
|
||||
cache = new IndexFieldDataCache.Soft();
|
||||
} else {
|
||||
throw new ElasticSearchIllegalArgumentException("cache type not supported [" + cacheType + "] for field [" + fieldNames.fullName() + "]");
|
||||
}
|
||||
|
||||
fieldData = builder.build(index, indexSettings, fieldNames, type, cache);
|
||||
|
|
|
@ -19,10 +19,10 @@
|
|||
|
||||
package org.elasticsearch.index.fielddata.ordinals;
|
||||
|
||||
import org.elasticsearch.ElasticSearchIllegalArgumentException;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.index.fielddata.util.IntArrayRef;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A thread safe ordinals abstraction. Ordinals can only be positive integers.
|
||||
*/
|
||||
|
@ -30,18 +30,16 @@ public interface Ordinals {
|
|||
|
||||
static class Factories {
|
||||
|
||||
public static Ordinals createFromFlatOrdinals(int[][] ordinals, int numOrds, Map<String, String> options) {
|
||||
String multiOrdinals = options.get("multi_ordinals");
|
||||
public static Ordinals createFromFlatOrdinals(int[][] ordinals, int numOrds, Settings settings) {
|
||||
String multiOrdinals = settings.get("multi_ordinals", "sparse");
|
||||
if ("flat".equals(multiOrdinals)) {
|
||||
return new MultiFlatArrayOrdinals(ordinals, numOrds);
|
||||
} else if ("sparse".equals(multiOrdinals)) {
|
||||
int multiOrdinalsMaxDocs = settings.getAsInt("multi_ordinals_max_docs", 16777216 /*Equal to 64MB per storage array*/);
|
||||
return new SparseMultiArrayOrdinals(ordinals, numOrds, multiOrdinalsMaxDocs);
|
||||
} else {
|
||||
throw new ElasticSearchIllegalArgumentException("no applicable fielddata multi_ordinals value, got [" + multiOrdinals + "]");
|
||||
}
|
||||
int multiOrdinalsMaxDocs = 16777216; // Equal to 64MB per storage array
|
||||
String multiOrdinalsMaxDocsVal = options.get("multi_ordinals_max_docs");
|
||||
if (multiOrdinalsMaxDocsVal != null) {
|
||||
multiOrdinalsMaxDocs = Integer.valueOf(multiOrdinalsMaxDocsVal);
|
||||
}
|
||||
|
||||
return new SparseMultiArrayOrdinals(ordinals, numOrds, multiOrdinalsMaxDocs);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -149,7 +149,7 @@ public class ByteArrayIndexFieldData extends AbstractIndexFieldData<ByteArrayAto
|
|||
return new ByteArrayAtomicFieldData.WithOrdinals(
|
||||
values.toArray(new byte[values.size()]),
|
||||
reader.maxDoc(),
|
||||
Ordinals.Factories.createFromFlatOrdinals(nativeOrdinals, termOrd, fieldDataType.getOptions())
|
||||
Ordinals.Factories.createFromFlatOrdinals(nativeOrdinals, termOrd, fieldDataType.getSettings())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -145,7 +145,7 @@ public class ConcreteBytesRefIndexFieldData extends AbstractIndexFieldData<Concr
|
|||
}
|
||||
return new ConcreteBytesRefAtomicFieldData(
|
||||
values.toArray(new BytesRef[values.size()]),
|
||||
Ordinals.Factories.createFromFlatOrdinals(nativeOrdinals, termOrd, fieldDataType.getOptions())
|
||||
Ordinals.Factories.createFromFlatOrdinals(nativeOrdinals, termOrd, fieldDataType.getSettings())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -149,7 +149,7 @@ public class DoubleArrayIndexFieldData extends AbstractIndexFieldData<DoubleArra
|
|||
return new DoubleArrayAtomicFieldData.WithOrdinals(
|
||||
values.toArray(new double[values.size()]),
|
||||
reader.maxDoc(),
|
||||
Ordinals.Factories.createFromFlatOrdinals(nativeOrdinals, termOrd, fieldDataType.getOptions())
|
||||
Ordinals.Factories.createFromFlatOrdinals(nativeOrdinals, termOrd, fieldDataType.getSettings())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -149,7 +149,7 @@ public class FloatArrayIndexFieldData extends AbstractIndexFieldData<FloatArrayA
|
|||
return new FloatArrayAtomicFieldData.WithOrdinals(
|
||||
values.toArray(new float[values.size()]),
|
||||
reader.maxDoc(),
|
||||
Ordinals.Factories.createFromFlatOrdinals(nativeOrdinals, termOrd, fieldDataType.getOptions())
|
||||
Ordinals.Factories.createFromFlatOrdinals(nativeOrdinals, termOrd, fieldDataType.getSettings())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -153,7 +153,7 @@ public class GeoPointDoubleArrayIndexFieldData extends AbstractIndexFieldData<Ge
|
|||
lon.toArray(new double[lon.size()]),
|
||||
lat.toArray(new double[lat.size()]),
|
||||
reader.maxDoc(),
|
||||
Ordinals.Factories.createFromFlatOrdinals(nativeOrdinals, termOrd, fieldDataType.getOptions())
|
||||
Ordinals.Factories.createFromFlatOrdinals(nativeOrdinals, termOrd, fieldDataType.getSettings())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -149,7 +149,7 @@ public class IntArrayIndexFieldData extends AbstractIndexFieldData<IntArrayAtomi
|
|||
return new IntArrayAtomicFieldData.WithOrdinals(
|
||||
values.toArray(new int[values.size()]),
|
||||
reader.maxDoc(),
|
||||
Ordinals.Factories.createFromFlatOrdinals(nativeOrdinals, termOrd, fieldDataType.getOptions())
|
||||
Ordinals.Factories.createFromFlatOrdinals(nativeOrdinals, termOrd, fieldDataType.getSettings())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -149,7 +149,7 @@ public class LongArrayIndexFieldData extends AbstractIndexFieldData<LongArrayAto
|
|||
return new LongArrayAtomicFieldData.WithOrdinals(
|
||||
values.toArray(new long[values.size()]),
|
||||
reader.maxDoc(),
|
||||
Ordinals.Factories.createFromFlatOrdinals(nativeOrdinals, termOrd, fieldDataType.getOptions())
|
||||
Ordinals.Factories.createFromFlatOrdinals(nativeOrdinals, termOrd, fieldDataType.getSettings())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -178,7 +178,7 @@ public class PagedBytesIndexFieldData extends AbstractIndexFieldData<PagedBytesA
|
|||
return new PagedBytesAtomicFieldData(
|
||||
bytesReader,
|
||||
termOrdToBytesOffsetReader,
|
||||
Ordinals.Factories.createFromFlatOrdinals(nativeOrdinals, termOrd, fieldDataType.getOptions())
|
||||
Ordinals.Factories.createFromFlatOrdinals(nativeOrdinals, termOrd, fieldDataType.getSettings())
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -149,7 +149,7 @@ public class ShortArrayIndexFieldData extends AbstractIndexFieldData<ShortArrayA
|
|||
return new ShortArrayAtomicFieldData.WithOrdinals(
|
||||
values.toArray(new short[values.size()]),
|
||||
reader.maxDoc(),
|
||||
Ordinals.Factories.createFromFlatOrdinals(nativeOrdinals, termOrd, fieldDataType.getOptions())
|
||||
Ordinals.Factories.createFromFlatOrdinals(nativeOrdinals, termOrd, fieldDataType.getSettings())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.apache.lucene.index.Term;
|
|||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.lucene.Lucene;
|
||||
import org.elasticsearch.common.lucene.uid.UidField;
|
||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.index.codec.postingsformat.PostingsFormatProvider;
|
||||
import org.elasticsearch.index.fielddata.FieldDataType;
|
||||
|
@ -129,7 +130,7 @@ public class UidFieldMapper extends AbstractFieldMapper<Uid> implements Internal
|
|||
|
||||
@Override
|
||||
public FieldDataType fieldDataType() {
|
||||
return new FieldDataType("string", "paged_bytes");
|
||||
return new FieldDataType("string", ImmutableSettings.builder().put("format", "paged_bytes"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -36,6 +36,7 @@ import org.elasticsearch.common.bytes.BytesReference;
|
|||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.logging.ESLogger;
|
||||
import org.elasticsearch.common.lucene.Lucene;
|
||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
|
@ -386,7 +387,7 @@ public class PercolatorExecutor extends AbstractIndexComponent {
|
|||
this.percolatorIndex = percolatorIndex;
|
||||
this.matches = matches;
|
||||
// TODO: when we move to a UID level mapping def on the index level, we can use that one, now, its per type, and we can't easily choose one
|
||||
this.uidFieldData = percolatorIndex.fieldData().getForField(new FieldMapper.Names(UidFieldMapper.NAME), new FieldDataType("string", "paged_bytes"));
|
||||
this.uidFieldData = percolatorIndex.fieldData().getForField(new FieldMapper.Names(UidFieldMapper.NAME), new FieldDataType("string", ImmutableSettings.builder().put("format", "paged_bytes")));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
package org.elasticsearch.test.unit.index.fielddata;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||
import org.elasticsearch.index.fielddata.FieldDataType;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -30,6 +30,6 @@ public class ConcreteBytesStringFieldDataTests extends StringFieldDataTests {
|
|||
|
||||
@Override
|
||||
protected FieldDataType getFieldDataType() {
|
||||
return new FieldDataType("string", "concrete_bytes", ImmutableMap.<String, String>of());
|
||||
return new FieldDataType("string", ImmutableSettings.builder().put("format", "concrete_bytes"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
package org.elasticsearch.test.unit.index.fielddata;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||
import org.elasticsearch.index.fielddata.FieldDataType;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -30,6 +30,6 @@ public class PagedBytesStringFieldDataTests extends StringFieldDataTests {
|
|||
|
||||
@Override
|
||||
protected FieldDataType getFieldDataType() {
|
||||
return new FieldDataType("string", "paged_bytes", ImmutableMap.<String, String>of());
|
||||
return new FieldDataType("string", ImmutableSettings.builder().put("format", "paged_bytes"));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue