org.hibernate.search.backend.elasticsearch.cfg.ElasticsearchIndexSettings Maven / Gradle / Ivy
/*
 * Hibernate Search, full-text search for your domain model
 *
 * License: GNU Lesser General Public License (LGPL), version 2.1 or later
 * See the lgpl.txt file in the root directory or .
 */
package org.hibernate.search.backend.elasticsearch.cfg;
import org.hibernate.search.backend.elasticsearch.analysis.ElasticsearchAnalysisConfigurer;
import org.hibernate.search.backend.elasticsearch.index.DynamicMapping;
import org.hibernate.search.backend.elasticsearch.index.IndexStatus;
/**
 * Configuration properties for Elasticsearch indexes.
 * 
 * Constants in this class are to be appended to a prefix to form a property key;
 * see {@link org.hibernate.search.engine.cfg.IndexSettings} for details.
 */
public final class ElasticsearchIndexSettings {
	private ElasticsearchIndexSettings() {
	}
	/**
	 * The analysis configurer applied to this index.
	 * 
	 * Expects a single-valued or multi-valued reference to beans of type {@link ElasticsearchAnalysisConfigurer}.
	 * 
	 * Defaults to no value.
	 *
	 * @see org.hibernate.search.engine.cfg The core documentation of configuration properties,
	 * which includes a description of the "multi-valued bean reference" properties and accepted values.
	 */
	public static final String ANALYSIS_CONFIGURER = "analysis.configurer";
	/**
	 * The minimal required status of an index on startup, before Hibernate Search can start using it.
	 * 
	 * Expects an {@link IndexStatus} value, or a String representation of such value.
	 * 
	 * Defaults to {@code yellow} when targeting an Elasticsearch distribution that supports index status checking,
	 * and to no value (no requirement) when targeting an Elasticsearch distribution
	 * that does not support index status checking (like Amazon OpenSearch Serverless).
	 */
	public static final String SCHEMA_MANAGEMENT_MINIMAL_REQUIRED_STATUS = "schema_management.minimal_required_status";
	/**
	 * The timeout when waiting for the {@link #SCHEMA_MANAGEMENT_MINIMAL_REQUIRED_STATUS required status}.
	 * 
	 * Expects a positive Integer value in milliseconds, such as {@code 60000},
	 * or a String that can be parsed into such Integer value.
	 * 
	 * Defaults to {@link Defaults#SCHEMA_MANAGEMENT_MINIMAL_REQUIRED_STATUS_WAIT_TIMEOUT}.
	 */
	public static final String SCHEMA_MANAGEMENT_MINIMAL_REQUIRED_STATUS_WAIT_TIMEOUT =
			"schema_management.minimal_required_status_wait_timeout";
	/**
	 * The path to a settings file, allowing custom settings for indexes created by Hibernate Search as part of schema management.
	 * 
	 * Expects a string representing the path to a UTF-8-encoded file in the classpath.
	 * The file must contain index settings expressed in JSON format,
	 * with the exact same syntax as expected by the Elasticsearch server under the "settings" property
	 * when creating an index.
	 * For example, if the file content is {"index.codec": "best_compression"},
	 * it will set {@code index.codec} to {@code best_compression}.
	 * 
	 * Note that the settings generated by Hibernate Search will be overridden in case of conflict of some definitions.
	 * For instance, if an analyzer "myAnalyzer" is defined by the {@link #ANALYSIS_CONFIGURER} and this settings file,
	 * the definition from the settings file will take precedence.
	 * If it is only defined in either the analysis configurer or the settings file,
	 * but not both, it will be preserved as-is.
	 * 
	 * Defaults to no value, meaning only index settings generated by Hibernate Search will be used.
	 */
	public static final String SCHEMA_MANAGEMENT_SETTINGS_FILE = "schema_management.settings_file";
	/**
	 * The path to a mappings file, allowing custom mappings for indexes created by Hibernate Search as part of schema management.
	 * 
	 * Expects a string representing the path to a UTF-8-encoded file in the classpath.
	 * The file must contain index settings expressed in JSON format,
	 * with the exact same syntax as expected by the Elasticsearch server under the "mappings" property
	 * when defining the mapping for an index.
	 * 
	 * The file does not need to contain the full mapping: Hibernate Search will automatically inject
	 * missing properties (index fields) in the given mapping.
	 * 
	 * Conflicts between the given mapping and the mapping generated by Hibernate Search will be handled as follows:
	 * 
	 * - Mapping parameters other than {@code properties} at the mapping root will be
	 * those from the given mapping; those generated by Hibernate Search will be ignored.
 
	 * - {@code properties} will be merged, using properties defined in both the
	 * given mapping and the mapping generated by Hibernate Search.
	 * If a property is defined on both sides, mapping parameters from the given mapping
	 * will be used, except for {@code properties},
	 * which will be merged recursively in the same way.
	 * 
 
	 * 
	 * Defaults to no value, meaning only index mappings generated by Hibernate Search will be used.
	 */
	public static final String SCHEMA_MANAGEMENT_MAPPING_FILE = "schema_management.mapping_file";
	/**
	 * The default for the {@code dynamic_mapping} attribute in the Elasticsearch mapping.
	 * 
	 * In case of dynamic fields with field templates, this setting will be ignored,
	 * since field templates force {@code dynamic_mapping} to {@link DynamicMapping#TRUE}.
	 * 
	 * Defaults to {@link Defaults#DYNAMIC_MAPPING}.
	 *
	 * @see DynamicMapping
	 */
	public static final String DYNAMIC_MAPPING = "dynamic_mapping";
	/**
	 * The prefix for indexing-related property keys.
	 */
	public static final String INDEXING_PREFIX = "indexing.";
	/**
	 * The number of indexing queues assigned to each index.
	 * 
	 * Expects a strictly positive integer value,
	 * or a string that can be parsed into an integer value.
	 * 
	 * Defaults to {@link Defaults#INDEXING_QUEUE_COUNT}.
	 * 
	 * See the reference documentation, section "Elasticsearch backend - Indexing",
	 * for more information about this setting and its implications.
	 */
	public static final String INDEXING_QUEUE_COUNT = INDEXING_PREFIX + IndexingRadicals.QUEUE_COUNT;
	/**
	 * The size of indexing queues.
	 * 
	 * Expects a strictly positive integer value,
	 * or a string that can be parsed into an integer value.
	 * 
	 * See the reference documentation, section "Elasticsearch backend - Indexing",
	 * for more information about this setting and its implications.
	 * 
	 * Defaults to {@link Defaults#INDEXING_QUEUE_SIZE}.
	 */
	public static final String INDEXING_QUEUE_SIZE = INDEXING_PREFIX + IndexingRadicals.QUEUE_SIZE;
	/**
	 * The maximum size of bulk requests created when processing indexing queues.
	 * 
	 * Expects a strictly positive integer value,
	 * or a string that can be parsed into an integer value.
	 * 
	 * See the reference documentation, section "Elasticsearch backend - Indexing",
	 * for more information about this setting and its implications.
	 * 
	 * Defaults to {@link Defaults#INDEXING_MAX_BULK_SIZE}.
	 */
	public static final String INDEXING_MAX_BULK_SIZE = INDEXING_PREFIX + IndexingRadicals.MAX_BULK_SIZE;
	/**
	 * Configuration property keys for indexing, without the {@link #INDEXING_PREFIX prefix}.
	 */
	public static final class IndexingRadicals {
		private IndexingRadicals() {
		}
		public static final String QUEUE_COUNT = "queue_count";
		public static final String QUEUE_SIZE = "queue_size";
		public static final String MAX_BULK_SIZE = "max_bulk_size";
	}
	/**
	 * Default values for the different settings if no values are given.
	 */
	public static final class Defaults {
		private Defaults() {
		}
		/**
		 * @deprecated The default for the {@link ElasticsearchIndexSettings#SCHEMA_MANAGEMENT_MINIMAL_REQUIRED_STATUS} property
		 * is now dynamic and depends on the targeted Elasticsearch distribution.
		 * @see ElasticsearchIndexSettings#SCHEMA_MANAGEMENT_MINIMAL_REQUIRED_STATUS
		 */
		@Deprecated
		public static final IndexStatus SCHEMA_MANAGEMENT_MINIMAL_REQUIRED_STATUS = IndexStatus.YELLOW;
		public static final int SCHEMA_MANAGEMENT_MINIMAL_REQUIRED_STATUS_WAIT_TIMEOUT = 10_000;
		public static final int INDEXING_QUEUE_COUNT = 10;
		public static final int INDEXING_QUEUE_SIZE = 1000;
		public static final int INDEXING_MAX_BULK_SIZE = 100;
		public static final DynamicMapping DYNAMIC_MAPPING = DynamicMapping.STRICT;
	}
}