org.elasticsearch.index.mapper.IgnoredFieldMapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of elasticsearch Show documentation
Show all versions of elasticsearch Show documentation
Elasticsearch subproject :server
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
package org.elasticsearch.index.mapper;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.FieldType;
import org.apache.lucene.index.IndexOptions;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermRangeQuery;
import org.elasticsearch.index.query.SearchExecutionContext;
import java.util.Collections;
/**
* A field mapper that records fields that have been ignored because they were malformed.
*/
public final class IgnoredFieldMapper extends MetadataFieldMapper {
public static final String NAME = "_ignored";
public static final String CONTENT_TYPE = "_ignored";
public static class Defaults {
public static final String NAME = IgnoredFieldMapper.NAME;
public static final FieldType FIELD_TYPE = new FieldType();
static {
FIELD_TYPE.setIndexOptions(IndexOptions.DOCS);
FIELD_TYPE.setTokenized(false);
FIELD_TYPE.setStored(true);
FIELD_TYPE.setOmitNorms(true);
FIELD_TYPE.freeze();
}
}
private static final IgnoredFieldMapper INSTANCE = new IgnoredFieldMapper();
public static final TypeParser PARSER = new FixedTypeParser(c -> INSTANCE);
public static final class IgnoredFieldType extends StringFieldType {
public static final IgnoredFieldType INSTANCE = new IgnoredFieldType();
private IgnoredFieldType() {
super(NAME, true, true, false, TextSearchInfo.SIMPLE_MATCH_ONLY, Collections.emptyMap());
}
@Override
public String typeName() {
return CONTENT_TYPE;
}
@Override
public Query existsQuery(SearchExecutionContext context) {
// This query is not performance sensitive, it only helps assess
// quality of the data, so we may use a slow query. It shouldn't
// be too slow in practice since the number of unique terms in this
// field is bounded by the number of fields in the mappings.
return new TermRangeQuery(name(), null, null, true, true);
}
@Override
public ValueFetcher valueFetcher(SearchExecutionContext context, String format) {
return new StoredValueFetcher(context.lookup(), NAME);
}
}
private IgnoredFieldMapper() {
super(IgnoredFieldType.INSTANCE);
}
@Override
public void postParse(DocumentParserContext context) {
for (String field : context.getIgnoredFields()) {
context.doc().add(new Field(NAME, field, Defaults.FIELD_TYPE));
}
}
@Override
protected String contentType() {
return CONTENT_TYPE;
}
}