/* * Copyright OpenSearch Contributors * 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.sdk.api; import org.opensearch.index.mapper.Mapper; import org.opensearch.index.mapper.MetadataFieldMapper; import org.opensearch.sdk.Extension; import java.util.Collections; import java.util.Map; import java.util.function.Function; import java.util.function.Predicate; /** * An extension point for {@link Extension} implementations to add custom mappers */ public interface MapperExtension { /** * Returns additional mapper implementations added by this extension. *

* The key of the returned {@link Map} is the unique name for the mapper which will be used * as the mapping {@code type}, and the value is a {@link Mapper.TypeParser} to parse the * mapper settings into a {@link Mapper}. * @return a map of unique mapper names to their corresponding type parsers. */ default Map getMappers() { return Collections.emptyMap(); } /** * Returns additional metadata mapper implementations added by this extension. *

* The key of the returned {@link Map} is the unique name for the metadata mapper, which * is used in the mapping json to configure the metadata mapper, and the value is a * {@link MetadataFieldMapper.TypeParser} to parse the mapper settings into a * {@link MetadataFieldMapper}. * @return a map of metadata mapper names to their corresponding type parsers. */ default Map getMetadataMappers() { return Collections.emptyMap(); } /** * Returns a function that filters the fields returned by get mappings, get index, get field mappings, and field capabilities API. * The returned function takes an index name as input and returns a predicate that specifies which fields should be returned by the API. * The predicate takes a field name as input and returns true to include the field or false to exclude it. * @return a function that filters the fields returned by certain APIs. */ default Function> getFieldFilter() { return NOOP_FIELD_FILTER; } /** * The default field predicate applied, which doesn't filter anything. That means that by default get mappings, get index * get field mappings and field capabilities API will return every field that's present in the mappings. */ Predicate NOOP_FIELD_PREDICATE = field -> true; /** * The default field filter applied, which doesn't filter anything. That means that by default get mappings, get index * get field mappings and field capabilities API will return every field that's present in the mappings. */ Function> NOOP_FIELD_FILTER = index -> NOOP_FIELD_PREDICATE; }