From a59f1e4ea73235c1c7343e319fec225acac0683f Mon Sep 17 00:00:00 2001 From: Mohammad Qureshi Date: Tue, 5 Mar 2024 13:10:10 -0800 Subject: [PATCH 01/13] Add initial implementation of DerivedFieldMapper class Signed-off-by: Mohammad Qureshi --- .../index/mapper/DerivedFieldMapper.java | 173 ++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100644 server/src/main/java/org/opensearch/index/mapper/DerivedFieldMapper.java diff --git a/server/src/main/java/org/opensearch/index/mapper/DerivedFieldMapper.java b/server/src/main/java/org/opensearch/index/mapper/DerivedFieldMapper.java new file mode 100644 index 0000000000000..7ca71afa717b1 --- /dev/null +++ b/server/src/main/java/org/opensearch/index/mapper/DerivedFieldMapper.java @@ -0,0 +1,173 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.index.mapper; + +import org.apache.lucene.document.FieldType; +import org.apache.lucene.index.IndexOptions; +import org.apache.lucene.search.Query; +import org.opensearch.common.Nullable; +import org.opensearch.index.query.QueryShardContext; +import org.opensearch.script.Script; +import org.opensearch.search.lookup.SearchLookup; + +import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +/** + * A field mapper for derived fields + * + * @opensearch.internal + */ +public class DerivedFieldMapper extends ParametrizedFieldMapper { + + public static final String CONTENT_TYPE = "derived_field"; + + /** + * Default parameters for the boolean field mapper + * + * @opensearch.internal + */ + public static class Defaults { + public static final FieldType FIELD_TYPE = new FieldType(); + + static { + FIELD_TYPE.setOmitNorms(true); + FIELD_TYPE.setStored(false); + FIELD_TYPE.setTokenized(false); + FIELD_TYPE.setIndexOptions(IndexOptions.NONE); + FIELD_TYPE.freeze(); + } + } + + private static DerivedFieldMapper toType(FieldMapper in) { + return (DerivedFieldMapper) in; + } + + /** + * Builder for this field mapper + * + * @opensearch.internal + */ + public static class Builder extends ParametrizedFieldMapper.Builder { + + // TODO: The type of parameter may change here if the actual underlying FieldType object is needed + private final Parameter type = Parameter.stringParam( + "type", + false, + m -> toType(m).type, + "text" + ); + + private final Parameter