本文整理汇总了Java中org.elasticsearch.index.mapper.MappedFieldType类的典型用法代码示例。如果您正苦于以下问题:Java MappedFieldType类的具体用法?Java MappedFieldType怎么用?Java MappedFieldType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MappedFieldType类属于org.elasticsearch.index.mapper包,在下文中一共展示了MappedFieldType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: get
import org.elasticsearch.index.mapper.MappedFieldType; //导入依赖的package包/类
@Override
public ScriptDocValues<?> get(Object key) {
// assume its a string...
String fieldName = key.toString();
ScriptDocValues<?> scriptValues = localCacheFieldData.get(fieldName);
if (scriptValues == null) {
final MappedFieldType fieldType = mapperService.fullName(fieldName);
if (fieldType == null) {
throw new IllegalArgumentException("No field found for [" + fieldName + "] in mapping with types " + Arrays.toString(types) + "");
}
// load fielddata on behalf of the script: otherwise it would need additional permissions
// to deal with pagedbytes/ramusagestimator/etc
scriptValues = AccessController.doPrivileged(new PrivilegedAction<ScriptDocValues<?>>() {
@Override
public ScriptDocValues<?> run() {
return fieldDataService.getForField(fieldType).load(reader).getScriptValues();
}
});
localCacheFieldData.put(fieldName, scriptValues);
}
scriptValues.setNextDocId(docId);
return scriptValues;
}
示例2: loadFieldData
import org.elasticsearch.index.mapper.MappedFieldType; //导入依赖的package包/类
private FieldLookup loadFieldData(String name) {
FieldLookup data = cachedFieldData.get(name);
if (data == null) {
MappedFieldType fieldType = mapperService.fullName(name);
if (fieldType == null) {
throw new IllegalArgumentException("No field found for [" + name + "] in mapping with types " + Arrays.toString(types) + "");
}
data = new FieldLookup(fieldType);
cachedFieldData.put(name, data);
}
if (data.fields() == null) {
String fieldName = data.fieldType().name();
fieldVisitor.reset(fieldName);
try {
reader.document(docId, fieldVisitor);
fieldVisitor.postProcess(data.fieldType());
data.fields(singletonMap(name, fieldVisitor.fields().get(data.fieldType().name())));
} catch (IOException e) {
throw new ElasticsearchParseException("failed to load field [{}]", e, name);
}
}
return data;
}
示例3: doAssertLuceneQuery
import org.elasticsearch.index.mapper.MappedFieldType; //导入依赖的package包/类
@Override
protected void doAssertLuceneQuery(TermQueryBuilder queryBuilder, Query query, SearchContext context) throws IOException {
assertThat(query, either(instanceOf(TermQuery.class)).or(instanceOf(PointRangeQuery.class)));
MappedFieldType mapper = context.getQueryShardContext().fieldMapper(queryBuilder.fieldName());
if (query instanceof TermQuery) {
TermQuery termQuery = (TermQuery) query;
assertThat(termQuery.getTerm().field(), equalTo(queryBuilder.fieldName()));
if (mapper != null) {
Term term = ((TermQuery) mapper.termQuery(queryBuilder.value(), null)).getTerm();
assertThat(termQuery.getTerm(), equalTo(term));
} else {
assertThat(termQuery.getTerm().bytes(), equalTo(BytesRefs.toBytesRef(queryBuilder.value())));
}
} else {
assertEquals(query, mapper.termQuery(queryBuilder.value(), null));
}
}
示例4: parseVariable
import org.elasticsearch.index.mapper.MappedFieldType; //导入依赖的package包/类
private AbstractDistanceScoreFunction parseVariable(String fieldName, XContentParser parser, QueryShardContext context,
MultiValueMode mode) throws IOException {
//the field must exist, else we cannot read the value for the doc later
MappedFieldType fieldType = context.fieldMapper(fieldName);
if (fieldType == null) {
throw new ParsingException(parser.getTokenLocation(), "unknown field [{}]", fieldName);
}
// dates and time and geo need special handling
parser.nextToken();
if (fieldType instanceof DateFieldMapper.DateFieldType) {
return parseDateVariable(parser, context, fieldType, mode);
} else if (fieldType instanceof GeoPointFieldType) {
return parseGeoVariable(parser, context, fieldType, mode);
} else if (fieldType instanceof NumberFieldMapper.NumberFieldType) {
return parseNumberVariable(parser, context, fieldType, mode);
} else {
throw new ParsingException(parser.getTokenLocation(), "field [{}] is of type [{}], but only numeric types are supported.",
fieldName, fieldType);
}
}
示例5: doRewrite
import org.elasticsearch.index.mapper.MappedFieldType; //导入依赖的package包/类
@Override
protected QueryBuilder doRewrite(QueryRewriteContext queryRewriteContext) throws IOException {
final MappedFieldType.Relation relation = getRelation(queryRewriteContext);
switch (relation) {
case DISJOINT:
return new MatchNoneQueryBuilder();
case WITHIN:
if (from != null || to != null || format != null || timeZone != null) {
RangeQueryBuilder newRangeQuery = new RangeQueryBuilder(fieldName);
newRangeQuery.from(null);
newRangeQuery.to(null);
newRangeQuery.format = null;
newRangeQuery.timeZone = null;
return newRangeQuery;
} else {
return this;
}
case INTERSECTS:
return this;
default:
throw new AssertionError();
}
}
示例6: checkCompatibility
import org.elasticsearch.index.mapper.MappedFieldType; //导入依赖的package包/类
@Override
public boolean checkCompatibility(MappedFieldType fieldType, List<String> conflicts, boolean strict, boolean reindex) {
boolean needReindex = super.checkCompatibility(fieldType, conflicts, strict, reindex);
BinaryFieldType other = (BinaryFieldType)fieldType;
if (tryUncompressing() != other.tryUncompressing()) {
conflicts.add("mapper [" + names().fullName() + "] has different [try_uncompressing] (IMPOSSIBLE)");
needReindex = true;
}
// if reindex is true, ignore above conflicts
if (reindex) {
conflicts.clear();
}
return needReindex;
}
示例7: loadFieldData
import org.elasticsearch.index.mapper.MappedFieldType; //导入依赖的package包/类
private FieldLookup loadFieldData(String name) {
FieldLookup data = cachedFieldData.get(name);
if (data == null) {
MappedFieldType fieldType = mapperService.smartNameFieldType(name, types);
if (fieldType == null) {
throw new IllegalArgumentException("No field found for [" + name + "] in mapping with types " + Arrays.toString(types) + "");
}
data = new FieldLookup(fieldType);
cachedFieldData.put(name, data);
}
if (data.fields() == null) {
String fieldName = data.fieldType().names().indexName();
fieldVisitor.reset(fieldName);
try {
reader.document(docId, fieldVisitor);
fieldVisitor.postProcess(data.fieldType());
data.fields(ImmutableMap.of(name, fieldVisitor.fields().get(data.fieldType().names().indexName())));
} catch (IOException e) {
throw new ElasticsearchParseException("failed to load field [{}]", e, name);
}
}
return data;
}
示例8: get
import org.elasticsearch.index.mapper.MappedFieldType; //导入依赖的package包/类
@Override
public Object get(Object key) {
// assume its a string...
String fieldName = key.toString();
ScriptDocValues scriptValues = localCacheFieldData.get(fieldName);
if (scriptValues == null) {
final MappedFieldType fieldType = mapperService.smartNameFieldType(fieldName, types);
if (fieldType == null) {
throw new IllegalArgumentException("No field found for [" + fieldName + "] in mapping with types " + Arrays.toString(types) + "");
}
// load fielddata on behalf of the script: otherwise it would need additional permissions
// to deal with pagedbytes/ramusagestimator/etc
scriptValues = AccessController.doPrivileged(new PrivilegedAction<ScriptDocValues>() {
@Override
public ScriptDocValues run() {
return fieldDataService.getForField(fieldType).load(reader).getScriptValues();
}
});
localCacheFieldData.put(fieldName, scriptValues);
}
scriptValues.setNextDocId(docId);
return scriptValues;
}
示例9: testDiversifiedSampler_noDocs
import org.elasticsearch.index.mapper.MappedFieldType; //导入依赖的package包/类
public void testDiversifiedSampler_noDocs() throws Exception {
Directory directory = newDirectory();
RandomIndexWriter indexWriter = new RandomIndexWriter(random(), directory);
indexWriter.close();
IndexReader indexReader = DirectoryReader.open(directory);
IndexSearcher indexSearcher = new IndexSearcher(indexReader);
MappedFieldType idFieldType = new KeywordFieldMapper.KeywordFieldType();
idFieldType.setName("id");
idFieldType.setHasDocValues(true);
MappedFieldType genreFieldType = new KeywordFieldMapper.KeywordFieldType();
genreFieldType.setName("genre");
genreFieldType.setHasDocValues(true);
DiversifiedAggregationBuilder builder = new DiversifiedAggregationBuilder("_name")
.field(genreFieldType.name())
.subAggregation(new TermsAggregationBuilder("terms", null).field("id"));
InternalSampler result = search(indexSearcher, new MatchAllDocsQuery(), builder, genreFieldType, idFieldType);
Terms terms = result.getAggregations().get("terms");
assertEquals(0, terms.getBuckets().size());
indexReader.close();
directory.close();
}
示例10: createCommonTermsQuery
import org.elasticsearch.index.mapper.MappedFieldType; //导入依赖的package包/类
public Query createCommonTermsQuery(String field, String queryText, Occur highFreqOccur, Occur lowFreqOccur, float maxTermFrequency, MappedFieldType fieldType) {
Query booleanQuery = createBooleanQuery(field, queryText, lowFreqOccur);
if (booleanQuery != null && booleanQuery instanceof BooleanQuery) {
BooleanQuery bq = (BooleanQuery) booleanQuery;
ExtendedCommonTermsQuery query = new ExtendedCommonTermsQuery(highFreqOccur, lowFreqOccur, maxTermFrequency, ((BooleanQuery)booleanQuery).isCoordDisabled(), fieldType);
for (BooleanClause clause : bq.clauses()) {
if (!(clause.getQuery() instanceof TermQuery)) {
return booleanQuery;
}
query.add(((TermQuery) clause.getQuery()).getTerm());
}
return query;
}
return booleanQuery;
}
示例11: postProcess
import org.elasticsearch.index.mapper.MappedFieldType; //导入依赖的package包/类
public void postProcess(MappedFieldType fieldType) {
if (uid != null) {
switch (field) {
case UidFieldMapper.NAME:
addValue(field, uid.toString());
break;
case IdFieldMapper.NAME:
addValue(field, uid.id());
break;
case TypeFieldMapper.NAME:
addValue(field, uid.type());
break;
}
}
if (fieldsValues == null) {
return;
}
List<Object> fieldValues = fieldsValues.get(fieldType.name());
if (fieldValues == null) {
return;
}
for (int i = 0; i < fieldValues.size(); i++) {
fieldValues.set(i, fieldType.valueForDisplay(fieldValues.get(i)));
}
}
示例12: ParentChildIndexFieldData
import org.elasticsearch.index.mapper.MappedFieldType; //导入依赖的package包/类
public ParentChildIndexFieldData(Index index, Settings indexSettings, MappedFieldType.Names fieldNames,
FieldDataType fieldDataType, IndexFieldDataCache cache, MapperService mapperService,
CircuitBreakerService breakerService) {
super(index, indexSettings, fieldNames, fieldDataType, cache);
this.breakerService = breakerService;
if (Version.indexCreated(indexSettings).before(Version.V_2_0_0_beta1)) {
parentTypes = new TreeSet<>();
for (DocumentMapper documentMapper : mapperService.docMappers(false)) {
beforeCreate(documentMapper);
}
mapperService.addTypeListener(this);
} else {
ImmutableSortedSet.Builder<String> builder = ImmutableSortedSet.naturalOrder();
for (DocumentMapper mapper : mapperService.docMappers(false)) {
ParentFieldMapper parentFieldMapper = mapper.parentFieldMapper();
if (parentFieldMapper.active()) {
builder.add(parentFieldMapper.type());
}
}
parentTypes = builder.build();
}
}
示例13: testMinDocCount
import org.elasticsearch.index.mapper.MappedFieldType; //导入依赖的package包/类
public void testMinDocCount() throws Exception {
try (Directory dir = newDirectory();
RandomIndexWriter w = new RandomIndexWriter(random(), dir)) {
for (long value : new long[] {7, 3, -10, -6, 5, 50}) {
Document doc = new Document();
doc.add(new SortedNumericDocValuesField("field", value));
w.addDocument(doc);
}
HistogramAggregationBuilder aggBuilder = new HistogramAggregationBuilder("my_agg")
.field("field")
.interval(10)
.minDocCount(2);
MappedFieldType fieldType = new NumberFieldMapper.NumberFieldType(NumberFieldMapper.NumberType.LONG);
fieldType.setName("field");
try (IndexReader reader = w.getReader()) {
IndexSearcher searcher = new IndexSearcher(reader);
Histogram histogram = searchAndReduce(searcher, new MatchAllDocsQuery(), aggBuilder, fieldType);
assertEquals(2, histogram.getBuckets().size());
assertEquals(-10d, histogram.getBuckets().get(0).getKey());
assertEquals(2, histogram.getBuckets().get(0).getDocCount());
assertEquals(0d, histogram.getBuckets().get(1).getKey());
assertEquals(3, histogram.getBuckets().get(1).getDocCount());
}
}
}
示例14: createCommonTermsQuery
import org.elasticsearch.index.mapper.MappedFieldType; //导入依赖的package包/类
public Query createCommonTermsQuery(String field,
String queryText,
BooleanClause.Occur highFreqOccur,
BooleanClause.Occur lowFreqOccur,
Float maxTermFrequency,
MappedFieldType mapper) {
Query booleanQuery = createBooleanQuery(field, queryText, lowFreqOccur);
if (booleanQuery != null && booleanQuery instanceof BooleanQuery) {
BooleanQuery bq = (BooleanQuery) booleanQuery;
ExtendedCommonTermsQuery query = new ExtendedCommonTermsQuery(
highFreqOccur, lowFreqOccur, maxTermFrequency,
((BooleanQuery)booleanQuery).isCoordDisabled(), mapper);
for (BooleanClause clause : bq.clauses()) {
if (!(clause.getQuery() instanceof TermQuery)) {
return booleanQuery;
}
query.add(((TermQuery) clause.getQuery()).getTerm());
}
return query;
}
return booleanQuery;
}
示例15: testCase
import org.elasticsearch.index.mapper.MappedFieldType; //导入依赖的package包/类
public void testCase(MappedFieldType ft,
CheckedConsumer<RandomIndexWriter, IOException> buildIndex,
Consumer<InternalExtendedStats> verify) throws IOException {
try (Directory directory = newDirectory();
RandomIndexWriter indexWriter = new RandomIndexWriter(random(), directory)) {
buildIndex.accept(indexWriter);
try (IndexReader reader = indexWriter.getReader()) {
IndexSearcher searcher = new IndexSearcher(reader);
ExtendedStatsAggregationBuilder aggBuilder = new ExtendedStatsAggregationBuilder("my_agg")
.field("field")
.sigma(randomDoubleBetween(0, 10, true));
InternalExtendedStats stats = search(searcher, new MatchAllDocsQuery(), aggBuilder, ft);
verify.accept(stats);
}
}
}