
org.elasticsearch.index.mapper.BooleanFieldMapper Maven / Gradle / Ivy
/*
* 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.document.SortedNumericDocValuesField;
import org.apache.lucene.document.StoredField;
import org.apache.lucene.index.IndexOptions;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermRangeQuery;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.elasticsearch.core.Booleans;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.IndexNumericFieldData.NumericType;
import org.elasticsearch.index.fielddata.plain.SortedNumericIndexFieldData;
import org.elasticsearch.index.query.SearchExecutionContext;
import org.elasticsearch.script.BooleanFieldScript;
import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptCompiler;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.lookup.FieldValues;
import org.elasticsearch.search.lookup.SearchLookup;
import org.elasticsearch.xcontent.XContentParser;
import java.io.IOException;
import java.time.ZoneId;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Supplier;
/**
* A field mapper for boolean fields.
*/
public class BooleanFieldMapper extends FieldMapper {
public static final String CONTENT_TYPE = "boolean";
public static class Defaults {
public static final FieldType FIELD_TYPE = new FieldType();
static {
FIELD_TYPE.setOmitNorms(true);
FIELD_TYPE.setIndexOptions(IndexOptions.DOCS);
FIELD_TYPE.setTokenized(false);
FIELD_TYPE.freeze();
}
}
public static class Values {
public static final BytesRef TRUE = new BytesRef("T");
public static final BytesRef FALSE = new BytesRef("F");
}
private static BooleanFieldMapper toType(FieldMapper in) {
return (BooleanFieldMapper) in;
}
public static class Builder extends FieldMapper.Builder {
private final Parameter docValues = Parameter.docValuesParam(m -> toType(m).hasDocValues, true);
private final Parameter indexed = Parameter.indexParam(m -> toType(m).indexed, true);
private final Parameter stored = Parameter.storeParam(m -> toType(m).stored, false);
private final Parameter nullValue = new Parameter<>(
"null_value",
false,
() -> null,
(n, c, o) -> o == null ? null : XContentMapValues.nodeBooleanValue(o),
m -> toType(m).nullValue
).acceptsNull();
private final Parameter boost = Parameter.boostParam();
private final Parameter