예제 #1
0
 public CreateIndexRequest(IndexName index, IndexState state) : this(index)
 {
     this.Settings   = state.Settings;
     this.Mappings   = state.Mappings;
     this.Aliases    = state.Aliases;
     this.Similarity = state.Similarity;
     CreateIndexRequest.RemoveReadOnlySettings(this.Settings);
 }
		public CreateIndexRequest(IndexName index, IndexState state) : this(index)
		{
			this.Settings = state.Settings;
			this.Mappings = state.Mappings;
			this.Aliases = state.Aliases;
			this.Similarity = state.Similarity;
			CreateIndexRequest.RemoveReadOnlySettings(this.Settings);
		}
        private async Task EnsureIndexExists(string currentIndexName, ElasticClient esClient)
        {
            IExistsResponse existsResult = await esClient.IndexExistsAsync(currentIndexName);
            if (!existsResult.IsValid)
            {
                this.ReportEsRequestError(existsResult, "Index exists check");
            }

            if (existsResult.Exists)
            {
                return;
            }

            // TODO: allow the consumer to fine-tune index settings
            IndexState indexState = new IndexState();
            indexState.Settings = new IndexSettings();
            indexState.Settings.NumberOfReplicas = 1;
            indexState.Settings.NumberOfShards = 5;
            indexState.Settings.Add("refresh_interval", "15s");

            ICreateIndexResponse createIndexResult = await esClient.CreateIndexAsync(currentIndexName, c => c.InitializeUsing(indexState));

            if (!createIndexResult.IsValid)
            {
                if (createIndexResult.ServerError != null &&
                    createIndexResult.ServerError.Error != null &&
                    string.Equals(createIndexResult.ServerError.Error.Type, "IndexAlreadyExistsException", StringComparison.OrdinalIgnoreCase))
                {
                    // This is fine, someone just beat us to create a new index.
                    return;
                }

                this.ReportEsRequestError(createIndexResult, "Create index");
            }
        }