allow to disable the optimization of removal of ords on single value numerics/geo field data
field data settings in the mappings can have ordinals=always option
This commit is contained in:
parent
54f685674b
commit
5af6343697
|
@ -35,6 +35,18 @@ import org.elasticsearch.index.settings.IndexSettings;
|
||||||
*/
|
*/
|
||||||
public interface IndexFieldData<FD extends AtomicFieldData> extends IndexComponent {
|
public interface IndexFieldData<FD extends AtomicFieldData> extends IndexComponent {
|
||||||
|
|
||||||
|
public static class CommonSettings {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should single value cross documents case be optimized to remove ords. Note, this optimization
|
||||||
|
* might not be supported by all Field Data implementations, but the ones that do, should consult
|
||||||
|
* this method to check if it should be done or not.
|
||||||
|
*/
|
||||||
|
public static boolean removeOrdsOnSingleValue(FieldDataType fieldDataType) {
|
||||||
|
return !"always".equals(fieldDataType.getSettings().get("ordinals"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The field name.
|
* The field name.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -100,7 +100,7 @@ public class ByteArrayIndexFieldData extends AbstractIndexFieldData<ByteArrayAto
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Ordinals build = builder.build(fieldDataType.getSettings());
|
Ordinals build = builder.build(fieldDataType.getSettings());
|
||||||
return build(reader, builder, build, new BuilderBytes() {
|
return build(reader, fieldDataType, builder, build, new BuilderBytes() {
|
||||||
@Override
|
@Override
|
||||||
public byte get(int index) {
|
public byte get(int index) {
|
||||||
return values.get(index);
|
return values.get(index);
|
||||||
|
@ -122,8 +122,8 @@ public class ByteArrayIndexFieldData extends AbstractIndexFieldData<ByteArrayAto
|
||||||
byte[] toArray();
|
byte[] toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
static ByteArrayAtomicFieldData build(AtomicReader reader, OrdinalsBuilder builder, Ordinals build, BuilderBytes values) {
|
static ByteArrayAtomicFieldData build(AtomicReader reader, FieldDataType fieldDataType, OrdinalsBuilder builder, Ordinals build, BuilderBytes values) {
|
||||||
if (!build.isMultiValued()) {
|
if (!build.isMultiValued() && CommonSettings.removeOrdsOnSingleValue(fieldDataType)) {
|
||||||
Docs ordinals = build.ordinals();
|
Docs ordinals = build.ordinals();
|
||||||
byte[] sValues = new byte[reader.maxDoc()];
|
byte[] sValues = new byte[reader.maxDoc()];
|
||||||
int maxDoc = reader.maxDoc();
|
int maxDoc = reader.maxDoc();
|
||||||
|
|
|
@ -101,7 +101,7 @@ public class DoubleArrayIndexFieldData extends AbstractIndexFieldData<DoubleArra
|
||||||
values.add(NumericUtils.sortableLongToDouble(NumericUtils.prefixCodedToLong(term)));
|
values.add(NumericUtils.sortableLongToDouble(NumericUtils.prefixCodedToLong(term)));
|
||||||
}
|
}
|
||||||
Ordinals build = builder.build(fieldDataType.getSettings());
|
Ordinals build = builder.build(fieldDataType.getSettings());
|
||||||
if (!build.isMultiValued()) {
|
if (!build.isMultiValued() && CommonSettings.removeOrdsOnSingleValue(fieldDataType)) {
|
||||||
Docs ordinals = build.ordinals();
|
Docs ordinals = build.ordinals();
|
||||||
double[] sValues = new double[reader.maxDoc()];
|
double[] sValues = new double[reader.maxDoc()];
|
||||||
int maxDoc = reader.maxDoc();
|
int maxDoc = reader.maxDoc();
|
||||||
|
|
|
@ -101,7 +101,7 @@ public class FloatArrayIndexFieldData extends AbstractIndexFieldData<FloatArrayA
|
||||||
values.add(NumericUtils.sortableIntToFloat(NumericUtils.prefixCodedToInt(term)));
|
values.add(NumericUtils.sortableIntToFloat(NumericUtils.prefixCodedToInt(term)));
|
||||||
}
|
}
|
||||||
Ordinals build = builder.build(fieldDataType.getSettings());
|
Ordinals build = builder.build(fieldDataType.getSettings());
|
||||||
if (!build.isMultiValued()) {
|
if (!build.isMultiValued() && CommonSettings.removeOrdsOnSingleValue(fieldDataType)) {
|
||||||
Docs ordinals = build.ordinals();
|
Docs ordinals = build.ordinals();
|
||||||
float[] sValues = new float[reader.maxDoc()];
|
float[] sValues = new float[reader.maxDoc()];
|
||||||
int maxDoc = reader.maxDoc();
|
int maxDoc = reader.maxDoc();
|
||||||
|
|
|
@ -106,7 +106,7 @@ public class GeoPointDoubleArrayIndexFieldData extends AbstractIndexFieldData<Ge
|
||||||
}
|
}
|
||||||
|
|
||||||
Ordinals build = builder.build(fieldDataType.getSettings());
|
Ordinals build = builder.build(fieldDataType.getSettings());
|
||||||
if (!build.isMultiValued()) {
|
if (!build.isMultiValued() && CommonSettings.removeOrdsOnSingleValue(fieldDataType)) {
|
||||||
Docs ordinals = build.ordinals();
|
Docs ordinals = build.ordinals();
|
||||||
double[] sLat = new double[reader.maxDoc()];
|
double[] sLat = new double[reader.maxDoc()];
|
||||||
double[] sLon = new double[reader.maxDoc()];
|
double[] sLon = new double[reader.maxDoc()];
|
||||||
|
|
|
@ -100,7 +100,7 @@ public class IntArrayIndexFieldData extends AbstractIndexFieldData<IntArrayAtomi
|
||||||
values.add(NumericUtils.prefixCodedToInt(term));
|
values.add(NumericUtils.prefixCodedToInt(term));
|
||||||
}
|
}
|
||||||
Ordinals build = builder.build(fieldDataType.getSettings());
|
Ordinals build = builder.build(fieldDataType.getSettings());
|
||||||
return build(reader, builder, build, new BuilderIntegers() {
|
return build(reader, fieldDataType, builder, build, new BuilderIntegers() {
|
||||||
@Override
|
@Override
|
||||||
public int get(int index) {
|
public int get(int index) {
|
||||||
return values.get(index);
|
return values.get(index);
|
||||||
|
@ -122,8 +122,8 @@ public class IntArrayIndexFieldData extends AbstractIndexFieldData<IntArrayAtomi
|
||||||
int[] toArray();
|
int[] toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
static IntArrayAtomicFieldData build(AtomicReader reader, OrdinalsBuilder builder, Ordinals build, BuilderIntegers values) {
|
static IntArrayAtomicFieldData build(AtomicReader reader, FieldDataType fieldDataType, OrdinalsBuilder builder, Ordinals build, BuilderIntegers values) {
|
||||||
if (!build.isMultiValued()) {
|
if (!build.isMultiValued() && CommonSettings.removeOrdsOnSingleValue(fieldDataType)) {
|
||||||
Docs ordinals = build.ordinals();
|
Docs ordinals = build.ordinals();
|
||||||
int[] sValues = new int[reader.maxDoc()];
|
int[] sValues = new int[reader.maxDoc()];
|
||||||
int maxDoc = reader.maxDoc();
|
int maxDoc = reader.maxDoc();
|
||||||
|
|
|
@ -114,7 +114,7 @@ public class LongArrayIndexFieldData extends AbstractIndexFieldData<AtomicNumeri
|
||||||
if (fieldDataType.getSettings().getAsBoolean("optimize_type", true)) {
|
if (fieldDataType.getSettings().getAsBoolean("optimize_type", true)) {
|
||||||
// since the default mapping for numeric is long, its worth optimizing the actual type used to represent the data
|
// since the default mapping for numeric is long, its worth optimizing the actual type used to represent the data
|
||||||
if (min >= Byte.MIN_VALUE && max <= Byte.MAX_VALUE) {
|
if (min >= Byte.MIN_VALUE && max <= Byte.MAX_VALUE) {
|
||||||
return ByteArrayIndexFieldData.build(reader, builder, build, new ByteArrayIndexFieldData.BuilderBytes() {
|
return ByteArrayIndexFieldData.build(reader, fieldDataType, builder, build, new ByteArrayIndexFieldData.BuilderBytes() {
|
||||||
@Override
|
@Override
|
||||||
public byte get(int index) {
|
public byte get(int index) {
|
||||||
return (byte) values.get(index);
|
return (byte) values.get(index);
|
||||||
|
@ -131,7 +131,7 @@ public class LongArrayIndexFieldData extends AbstractIndexFieldData<AtomicNumeri
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (min >= Short.MIN_VALUE && max <= Short.MAX_VALUE) {
|
} else if (min >= Short.MIN_VALUE && max <= Short.MAX_VALUE) {
|
||||||
return ShortArrayIndexFieldData.build(reader, builder, build, new ShortArrayIndexFieldData.BuilderShorts() {
|
return ShortArrayIndexFieldData.build(reader, fieldDataType, builder, build, new ShortArrayIndexFieldData.BuilderShorts() {
|
||||||
@Override
|
@Override
|
||||||
public short get(int index) {
|
public short get(int index) {
|
||||||
return (short) values.get(index);
|
return (short) values.get(index);
|
||||||
|
@ -148,7 +148,7 @@ public class LongArrayIndexFieldData extends AbstractIndexFieldData<AtomicNumeri
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (min >= Integer.MIN_VALUE && max <= Integer.MAX_VALUE) {
|
} else if (min >= Integer.MIN_VALUE && max <= Integer.MAX_VALUE) {
|
||||||
return IntArrayIndexFieldData.build(reader, builder, build, new IntArrayIndexFieldData.BuilderIntegers() {
|
return IntArrayIndexFieldData.build(reader, fieldDataType, builder, build, new IntArrayIndexFieldData.BuilderIntegers() {
|
||||||
@Override
|
@Override
|
||||||
public int get(int index) {
|
public int get(int index) {
|
||||||
return (int) values.get(index);
|
return (int) values.get(index);
|
||||||
|
@ -167,7 +167,7 @@ public class LongArrayIndexFieldData extends AbstractIndexFieldData<AtomicNumeri
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!build.isMultiValued()) {
|
if (!build.isMultiValued() && CommonSettings.removeOrdsOnSingleValue(fieldDataType)) {
|
||||||
Docs ordinals = build.ordinals();
|
Docs ordinals = build.ordinals();
|
||||||
long[] sValues = new long[reader.maxDoc()];
|
long[] sValues = new long[reader.maxDoc()];
|
||||||
int maxDoc = reader.maxDoc();
|
int maxDoc = reader.maxDoc();
|
||||||
|
|
|
@ -101,7 +101,7 @@ public class ShortArrayIndexFieldData extends AbstractIndexFieldData<ShortArrayA
|
||||||
}
|
}
|
||||||
|
|
||||||
Ordinals build = builder.build(fieldDataType.getSettings());
|
Ordinals build = builder.build(fieldDataType.getSettings());
|
||||||
return build(reader, builder, build, new BuilderShorts() {
|
return build(reader, fieldDataType, builder, build, new BuilderShorts() {
|
||||||
@Override
|
@Override
|
||||||
public short get(int index) {
|
public short get(int index) {
|
||||||
return values.get(index);
|
return values.get(index);
|
||||||
|
@ -123,8 +123,8 @@ public class ShortArrayIndexFieldData extends AbstractIndexFieldData<ShortArrayA
|
||||||
short[] toArray();
|
short[] toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
static ShortArrayAtomicFieldData build(AtomicReader reader, OrdinalsBuilder builder, Ordinals build, BuilderShorts values) {
|
static ShortArrayAtomicFieldData build(AtomicReader reader, FieldDataType fieldDataType, OrdinalsBuilder builder, Ordinals build, BuilderShorts values) {
|
||||||
if (!build.isMultiValued()) {
|
if (!build.isMultiValued() && CommonSettings.removeOrdsOnSingleValue(fieldDataType)) {
|
||||||
Docs ordinals = build.ordinals();
|
Docs ordinals = build.ordinals();
|
||||||
short[] sValues = new short[reader.maxDoc()];
|
short[] sValues = new short[reader.maxDoc()];
|
||||||
int maxDoc = reader.maxDoc();
|
int maxDoc = reader.maxDoc();
|
||||||
|
|
Loading…
Reference in New Issue