mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-17 18:35:25 +00:00
use FieldMapper.Names for fieldNames, and not just fieldName as string
This commit is contained in:
parent
7dc5cf9799
commit
e0b280f9b3
@ -3,30 +3,31 @@ package org.elasticsearch.index.fielddata;
|
|||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.index.AbstractIndexComponent;
|
import org.elasticsearch.index.AbstractIndexComponent;
|
||||||
import org.elasticsearch.index.Index;
|
import org.elasticsearch.index.Index;
|
||||||
|
import org.elasticsearch.index.mapper.FieldMapper;
|
||||||
import org.elasticsearch.index.settings.IndexSettings;
|
import org.elasticsearch.index.settings.IndexSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractIndexFieldData<FD extends AtomicFieldData> extends AbstractIndexComponent implements IndexFieldData<FD> {
|
public abstract class AbstractIndexFieldData<FD extends AtomicFieldData> extends AbstractIndexComponent implements IndexFieldData<FD> {
|
||||||
|
|
||||||
private final String fieldName;
|
private final FieldMapper.Names fieldNames;
|
||||||
protected final FieldDataType fieldDataType;
|
protected final FieldDataType fieldDataType;
|
||||||
protected final IndexFieldDataCache cache;
|
protected final IndexFieldDataCache cache;
|
||||||
|
|
||||||
public AbstractIndexFieldData(Index index, @IndexSettings Settings indexSettings, String fieldName, FieldDataType fieldDataType, IndexFieldDataCache cache) {
|
public AbstractIndexFieldData(Index index, @IndexSettings Settings indexSettings, FieldMapper.Names fieldNames, FieldDataType fieldDataType, IndexFieldDataCache cache) {
|
||||||
super(index, indexSettings);
|
super(index, indexSettings);
|
||||||
this.fieldName = fieldName;
|
this.fieldNames = fieldNames;
|
||||||
this.fieldDataType = fieldDataType;
|
this.fieldDataType = fieldDataType;
|
||||||
this.cache = cache;
|
this.cache = cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getFieldName() {
|
public FieldMapper.Names getFieldNames() {
|
||||||
return this.fieldName;
|
return this.fieldNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clear() {
|
public void clear() {
|
||||||
cache.clear(index, fieldName);
|
cache.clear(index, fieldNames.indexName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ import org.elasticsearch.common.Nullable;
|
|||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.index.Index;
|
import org.elasticsearch.index.Index;
|
||||||
import org.elasticsearch.index.IndexComponent;
|
import org.elasticsearch.index.IndexComponent;
|
||||||
|
import org.elasticsearch.index.mapper.FieldMapper;
|
||||||
import org.elasticsearch.index.settings.IndexSettings;
|
import org.elasticsearch.index.settings.IndexSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -35,7 +36,7 @@ public interface IndexFieldData<FD extends AtomicFieldData> extends IndexCompone
|
|||||||
/**
|
/**
|
||||||
* The field name.
|
* The field name.
|
||||||
*/
|
*/
|
||||||
String getFieldName();
|
FieldMapper.Names getFieldNames();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Are the values ordered? (in ascending manner).
|
* Are the values ordered? (in ascending manner).
|
||||||
@ -72,6 +73,6 @@ public interface IndexFieldData<FD extends AtomicFieldData> extends IndexCompone
|
|||||||
|
|
||||||
interface Builder {
|
interface Builder {
|
||||||
|
|
||||||
IndexFieldData build(Index index, @IndexSettings Settings indexSettings, String fieldName, FieldDataType type, IndexFieldDataCache cache);
|
IndexFieldData build(Index index, @IndexSettings Settings indexSettings, FieldMapper.Names fieldNames, FieldDataType type, IndexFieldDataCache cache);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@ import org.elasticsearch.index.Index;
|
|||||||
import org.elasticsearch.index.fielddata.plain.ConcreteBytesRefIndexFieldData;
|
import org.elasticsearch.index.fielddata.plain.ConcreteBytesRefIndexFieldData;
|
||||||
import org.elasticsearch.index.fielddata.plain.DoubleArrayIndexFieldData;
|
import org.elasticsearch.index.fielddata.plain.DoubleArrayIndexFieldData;
|
||||||
import org.elasticsearch.index.fielddata.plain.LongArrayIndexFieldData;
|
import org.elasticsearch.index.fielddata.plain.LongArrayIndexFieldData;
|
||||||
|
import org.elasticsearch.index.mapper.FieldMapper;
|
||||||
import org.elasticsearch.index.settings.IndexSettings;
|
import org.elasticsearch.index.settings.IndexSettings;
|
||||||
|
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
@ -86,7 +87,7 @@ public class IndexFieldDataService extends AbstractIndexComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public <IFD extends IndexFieldData> IFD getForField(String fieldName, FieldDataType type) {
|
public <IFD extends IndexFieldData> IFD getForField(FieldMapper.Names fieldNames, FieldDataType type) {
|
||||||
IndexFieldData fieldData = loadedFieldData.get(type.getType());
|
IndexFieldData fieldData = loadedFieldData.get(type.getType());
|
||||||
if (fieldData == null) {
|
if (fieldData == null) {
|
||||||
synchronized (loadedFieldData) {
|
synchronized (loadedFieldData) {
|
||||||
@ -100,7 +101,7 @@ public class IndexFieldDataService extends AbstractIndexComponent {
|
|||||||
builder = buildersByType.get(type.getType());
|
builder = buildersByType.get(type.getType());
|
||||||
}
|
}
|
||||||
if (builder == null) {
|
if (builder == null) {
|
||||||
throw new ElasticSearchIllegalArgumentException("failed to find field data builder for field " + fieldName + ", and type " + type);
|
throw new ElasticSearchIllegalArgumentException("failed to find field data builder for field " + fieldNames.fullName() + ", and type " + type);
|
||||||
}
|
}
|
||||||
|
|
||||||
IndexFieldDataCache cache;
|
IndexFieldDataCache cache;
|
||||||
@ -111,14 +112,14 @@ public class IndexFieldDataService extends AbstractIndexComponent {
|
|||||||
} else if ("soft".equals(cacheType)) {
|
} else if ("soft".equals(cacheType)) {
|
||||||
cache = new IndexFieldDataCache.Soft();
|
cache = new IndexFieldDataCache.Soft();
|
||||||
} else {
|
} else {
|
||||||
throw new ElasticSearchIllegalArgumentException("cache type not supported [" + cacheType + "] for field [" + fieldName + "]");
|
throw new ElasticSearchIllegalArgumentException("cache type not supported [" + cacheType + "] for field [" + fieldNames.fullName() + "]");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
cache = new IndexFieldDataCache.Resident();
|
cache = new IndexFieldDataCache.Resident();
|
||||||
}
|
}
|
||||||
|
|
||||||
fieldData = builder.build(index, indexSettings, fieldName, type, cache);
|
fieldData = builder.build(index, indexSettings, fieldNames, type, cache);
|
||||||
loadedFieldData.put(fieldName, fieldData);
|
loadedFieldData.put(fieldNames.indexName(), fieldData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ public class BytesRefFieldComparatorSource extends IndexFieldData.XFieldComparat
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FieldComparator<?> newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException {
|
public FieldComparator<?> newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException {
|
||||||
assert fieldname.equals(indexFieldData.getFieldName());
|
assert fieldname.equals(indexFieldData.getFieldNames().indexName());
|
||||||
if (indexFieldData.valuesOrdered() && indexFieldData instanceof IndexOrdinalFieldData) {
|
if (indexFieldData.valuesOrdered() && indexFieldData instanceof IndexOrdinalFieldData) {
|
||||||
return new BytesRefOrdValComparator((IndexOrdinalFieldData) indexFieldData, numHits);
|
return new BytesRefOrdValComparator((IndexOrdinalFieldData) indexFieldData, numHits);
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ public class DoubleValuesComparatorSource extends IndexFieldData.XFieldComparato
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FieldComparator<?> newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException {
|
public FieldComparator<?> newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException {
|
||||||
assert fieldname.equals(indexFieldData.getFieldName());
|
assert fieldname.equals(indexFieldData.getFieldNames().indexName());
|
||||||
|
|
||||||
double dMissingValue;
|
double dMissingValue;
|
||||||
if (missingValue == null || "_last".equals(missingValue)) {
|
if (missingValue == null || "_last".equals(missingValue)) {
|
||||||
|
@ -30,6 +30,7 @@ import org.elasticsearch.index.fielddata.fieldcomparator.BytesRefFieldComparator
|
|||||||
import org.elasticsearch.index.fielddata.ordinals.EmptyOrdinals;
|
import org.elasticsearch.index.fielddata.ordinals.EmptyOrdinals;
|
||||||
import org.elasticsearch.index.fielddata.ordinals.MultiFlatArrayOrdinals;
|
import org.elasticsearch.index.fielddata.ordinals.MultiFlatArrayOrdinals;
|
||||||
import org.elasticsearch.index.fielddata.ordinals.SingleArrayOrdinals;
|
import org.elasticsearch.index.fielddata.ordinals.SingleArrayOrdinals;
|
||||||
|
import org.elasticsearch.index.mapper.FieldMapper;
|
||||||
import org.elasticsearch.index.settings.IndexSettings;
|
import org.elasticsearch.index.settings.IndexSettings;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -41,13 +42,13 @@ public class ConcreteBytesRefIndexFieldData extends AbstractIndexFieldData<Concr
|
|||||||
public static class Builder implements IndexFieldData.Builder {
|
public static class Builder implements IndexFieldData.Builder {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IndexFieldData build(Index index, @IndexSettings Settings indexSettings, String fieldName, FieldDataType type, IndexFieldDataCache cache) {
|
public IndexFieldData build(Index index, @IndexSettings Settings indexSettings, FieldMapper.Names fieldNames, FieldDataType type, IndexFieldDataCache cache) {
|
||||||
return new ConcreteBytesRefIndexFieldData(index, indexSettings, fieldName, type, cache);
|
return new ConcreteBytesRefIndexFieldData(index, indexSettings, fieldNames, type, cache);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConcreteBytesRefIndexFieldData(Index index, @IndexSettings Settings indexSettings, String fieldName, FieldDataType fieldDataType, IndexFieldDataCache cache) {
|
public ConcreteBytesRefIndexFieldData(Index index, @IndexSettings Settings indexSettings, FieldMapper.Names fieldNames, FieldDataType fieldDataType, IndexFieldDataCache cache) {
|
||||||
super(index, indexSettings, fieldName, fieldDataType, cache);
|
super(index, indexSettings, fieldNames, fieldDataType, cache);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -72,7 +73,7 @@ public class ConcreteBytesRefIndexFieldData extends AbstractIndexFieldData<Concr
|
|||||||
public ConcreteBytesRefAtomicFieldData loadDirect(AtomicReaderContext context) throws Exception {
|
public ConcreteBytesRefAtomicFieldData loadDirect(AtomicReaderContext context) throws Exception {
|
||||||
AtomicReader reader = context.reader();
|
AtomicReader reader = context.reader();
|
||||||
|
|
||||||
Terms terms = reader.terms(getFieldName());
|
Terms terms = reader.terms(getFieldNames().indexName());
|
||||||
if (terms == null) {
|
if (terms == null) {
|
||||||
return new ConcreteBytesRefAtomicFieldData(new BytesRef[1], new EmptyOrdinals(reader.maxDoc()));
|
return new ConcreteBytesRefAtomicFieldData(new BytesRef[1], new EmptyOrdinals(reader.maxDoc()));
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,7 @@ import org.elasticsearch.index.Index;
|
|||||||
import org.elasticsearch.index.fielddata.*;
|
import org.elasticsearch.index.fielddata.*;
|
||||||
import org.elasticsearch.index.fielddata.fieldcomparator.DoubleValuesComparatorSource;
|
import org.elasticsearch.index.fielddata.fieldcomparator.DoubleValuesComparatorSource;
|
||||||
import org.elasticsearch.index.fielddata.ordinals.MultiFlatArrayOrdinals;
|
import org.elasticsearch.index.fielddata.ordinals.MultiFlatArrayOrdinals;
|
||||||
|
import org.elasticsearch.index.mapper.FieldMapper;
|
||||||
import org.elasticsearch.index.settings.IndexSettings;
|
import org.elasticsearch.index.settings.IndexSettings;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -42,13 +43,13 @@ public class DoubleArrayIndexFieldData extends AbstractIndexFieldData<DoubleArra
|
|||||||
public static class Builder implements IndexFieldData.Builder {
|
public static class Builder implements IndexFieldData.Builder {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IndexFieldData build(Index index, @IndexSettings Settings indexSettings, String fieldName, FieldDataType type, IndexFieldDataCache cache) {
|
public IndexFieldData build(Index index, @IndexSettings Settings indexSettings, FieldMapper.Names fieldNames, FieldDataType type, IndexFieldDataCache cache) {
|
||||||
return new DoubleArrayIndexFieldData(index, indexSettings, fieldName, type, cache);
|
return new DoubleArrayIndexFieldData(index, indexSettings, fieldNames, type, cache);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public DoubleArrayIndexFieldData(Index index, @IndexSettings Settings indexSettings, String fieldName, FieldDataType fieldDataType, IndexFieldDataCache cache) {
|
public DoubleArrayIndexFieldData(Index index, @IndexSettings Settings indexSettings, FieldMapper.Names fieldNames, FieldDataType fieldDataType, IndexFieldDataCache cache) {
|
||||||
super(index, indexSettings, fieldName, fieldDataType, cache);
|
super(index, indexSettings, fieldNames, fieldDataType, cache);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -80,7 +81,7 @@ public class DoubleArrayIndexFieldData extends AbstractIndexFieldData<DoubleArra
|
|||||||
public DoubleArrayAtomicFieldData loadDirect(AtomicReaderContext context) throws Exception {
|
public DoubleArrayAtomicFieldData loadDirect(AtomicReaderContext context) throws Exception {
|
||||||
AtomicReader reader = context.reader();
|
AtomicReader reader = context.reader();
|
||||||
|
|
||||||
Terms terms = reader.terms(getFieldName());
|
Terms terms = reader.terms(getFieldNames().indexName());
|
||||||
if (terms == null) {
|
if (terms == null) {
|
||||||
return new DoubleArrayAtomicFieldData.Single(new double[0], 0);
|
return new DoubleArrayAtomicFieldData.Single(new double[0], 0);
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,7 @@ import org.elasticsearch.index.Index;
|
|||||||
import org.elasticsearch.index.fielddata.*;
|
import org.elasticsearch.index.fielddata.*;
|
||||||
import org.elasticsearch.index.fielddata.fieldcomparator.DoubleValuesComparatorSource;
|
import org.elasticsearch.index.fielddata.fieldcomparator.DoubleValuesComparatorSource;
|
||||||
import org.elasticsearch.index.fielddata.ordinals.MultiFlatArrayOrdinals;
|
import org.elasticsearch.index.fielddata.ordinals.MultiFlatArrayOrdinals;
|
||||||
|
import org.elasticsearch.index.mapper.FieldMapper;
|
||||||
import org.elasticsearch.index.settings.IndexSettings;
|
import org.elasticsearch.index.settings.IndexSettings;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -42,13 +43,13 @@ public class LongArrayIndexFieldData extends AbstractIndexFieldData<LongArrayAto
|
|||||||
public static class Builder implements IndexFieldData.Builder {
|
public static class Builder implements IndexFieldData.Builder {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IndexFieldData build(Index index, @IndexSettings Settings indexSettings, String fieldName, FieldDataType type, IndexFieldDataCache cache) {
|
public IndexFieldData build(Index index, @IndexSettings Settings indexSettings, FieldMapper.Names fieldNames, FieldDataType type, IndexFieldDataCache cache) {
|
||||||
return new LongArrayIndexFieldData(index, indexSettings, fieldName, type, cache);
|
return new LongArrayIndexFieldData(index, indexSettings, fieldNames, type, cache);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public LongArrayIndexFieldData(Index index, @IndexSettings Settings indexSettings, String fieldName, FieldDataType fieldDataType, IndexFieldDataCache cache) {
|
public LongArrayIndexFieldData(Index index, @IndexSettings Settings indexSettings, FieldMapper.Names fieldNames, FieldDataType fieldDataType, IndexFieldDataCache cache) {
|
||||||
super(index, indexSettings, fieldName, fieldDataType, cache);
|
super(index, indexSettings, fieldNames, fieldDataType, cache);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -80,7 +81,7 @@ public class LongArrayIndexFieldData extends AbstractIndexFieldData<LongArrayAto
|
|||||||
public LongArrayAtomicFieldData loadDirect(AtomicReaderContext context) throws Exception {
|
public LongArrayAtomicFieldData loadDirect(AtomicReaderContext context) throws Exception {
|
||||||
AtomicReader reader = context.reader();
|
AtomicReader reader = context.reader();
|
||||||
|
|
||||||
Terms terms = reader.terms(getFieldName());
|
Terms terms = reader.terms(getFieldNames().indexName());
|
||||||
if (terms == null) {
|
if (terms == null) {
|
||||||
return new LongArrayAtomicFieldData.Single(new long[0], 0);
|
return new LongArrayAtomicFieldData.Single(new long[0], 0);
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ import org.elasticsearch.common.lucene.HashedBytesRef;
|
|||||||
import org.elasticsearch.common.lucene.Lucene;
|
import org.elasticsearch.common.lucene.Lucene;
|
||||||
import org.elasticsearch.index.Index;
|
import org.elasticsearch.index.Index;
|
||||||
import org.elasticsearch.index.fielddata.*;
|
import org.elasticsearch.index.fielddata.*;
|
||||||
|
import org.elasticsearch.index.mapper.FieldMapper;
|
||||||
import org.testng.annotations.AfterMethod;
|
import org.testng.annotations.AfterMethod;
|
||||||
import org.testng.annotations.BeforeMethod;
|
import org.testng.annotations.BeforeMethod;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
@ -50,7 +51,7 @@ public abstract class AbstractFieldDataTests {
|
|||||||
protected abstract FieldDataType getFieldDataType();
|
protected abstract FieldDataType getFieldDataType();
|
||||||
|
|
||||||
public <IFD extends IndexFieldData> IFD getForField(String fieldName) {
|
public <IFD extends IndexFieldData> IFD getForField(String fieldName) {
|
||||||
return ifdService.getForField(fieldName, getFieldDataType());
|
return ifdService.getForField(new FieldMapper.Names(fieldName), getFieldDataType());
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeMethod
|
@BeforeMethod
|
||||||
|
Loading…
x
Reference in New Issue
Block a user