|
@@ -0,0 +1,85 @@
|
|
|
+/*
|
|
|
+ * 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.analysis.common.synonyms;
|
|
|
+
|
|
|
+import org.elasticsearch.Version;
|
|
|
+import org.elasticsearch.cluster.metadata.IndexMetadata;
|
|
|
+import org.elasticsearch.common.settings.Settings;
|
|
|
+import org.elasticsearch.common.util.FeatureFlag;
|
|
|
+import org.elasticsearch.indices.SystemIndexDescriptor;
|
|
|
+import org.elasticsearch.xcontent.XContentBuilder;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.UncheckedIOException;
|
|
|
+
|
|
|
+import static org.elasticsearch.index.mapper.MapperService.SINGLE_MAPPING_NAME;
|
|
|
+import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder;
|
|
|
+
|
|
|
+public class SynonymsManagementAPIService {
|
|
|
+ private static final FeatureFlag SYNONYMS_API_FEATURE_FLAG = new FeatureFlag("synonyms_api");
|
|
|
+ public static final String SYNONYMS_INDEX = ".synonyms";
|
|
|
+ public static final String SYNONYMS_ORIGIN = "synonyms";
|
|
|
+
|
|
|
+ public static SystemIndexDescriptor getSystemIndexDescriptor() {
|
|
|
+ return SystemIndexDescriptor.builder()
|
|
|
+ .setIndexPattern(SYNONYMS_INDEX + "*")
|
|
|
+ .setDescription("Synonyms index for synonyms managed through APIs")
|
|
|
+ .setPrimaryIndex(SYNONYMS_INDEX)
|
|
|
+ .setMappings(mappings())
|
|
|
+ .setSettings(settings())
|
|
|
+ .setVersionMetaKey("version")
|
|
|
+ .setOrigin(SYNONYMS_ORIGIN)
|
|
|
+ .build();
|
|
|
+ }
|
|
|
+
|
|
|
+ private static XContentBuilder mappings() {
|
|
|
+ try {
|
|
|
+ XContentBuilder builder = jsonBuilder();
|
|
|
+ builder.startObject();
|
|
|
+ {
|
|
|
+ builder.startObject(SINGLE_MAPPING_NAME);
|
|
|
+ {
|
|
|
+ builder.startObject("_meta");
|
|
|
+ {
|
|
|
+ builder.field("version", Version.CURRENT.toString());
|
|
|
+ }
|
|
|
+ builder.endObject();
|
|
|
+ builder.field("dynamic", "strict");
|
|
|
+ builder.startObject("properties");
|
|
|
+ {
|
|
|
+ builder.startObject("synonyms");
|
|
|
+ {
|
|
|
+ builder.field("type", "object");
|
|
|
+ builder.field("enabled", "false");
|
|
|
+ }
|
|
|
+ builder.endObject();
|
|
|
+ }
|
|
|
+ builder.endObject();
|
|
|
+ }
|
|
|
+ builder.endObject();
|
|
|
+ }
|
|
|
+ builder.endObject();
|
|
|
+ return builder;
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new UncheckedIOException("Failed to build mappings for " + SYNONYMS_INDEX, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ static Settings settings() {
|
|
|
+ return Settings.builder()
|
|
|
+ .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
|
|
|
+ .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
|
|
|
+ .put(IndexMetadata.SETTING_AUTO_EXPAND_REPLICAS, "0-all")
|
|
|
+ .build();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static boolean isEnabled() {
|
|
|
+ return SYNONYMS_API_FEATURE_FLAG.isEnabled();
|
|
|
+ }
|
|
|
+}
|