private async Task SetupMappingsAsync(DiagnosticsSource source) { foreach (var indexName in source.GetIndexNames()) { var esUrl = _configurationValueProvider.GetValue(ConfigurationKeys.ElasticSearchUrl); await _elasticsearchClient.CreateIndexIfNotExistsAsync(esUrl, indexName); if (!await _elasticsearchClient.MappingExistsAsync(esUrl, indexName, source.ToTypeKey())) { var jsonPath = string.Format("{0}{1}.json", _configurationValueProvider.GetValue(ConfigurationKeys.MappingsPath), source.GetMappingName()); var response = await _nonAuthenticatingClient.GetAsync(jsonPath); if (response.Content == null) { throw new ApplicationException(response.ToString()); } var content = await response.Content.ReadAsStringAsync(); if (!response.IsSuccessStatusCode) { throw new InvalidOperationException(content); } var mapping = content.Replace("___type_name___", source.ToTypeKey()); await _elasticsearchClient.UpdateMappingAsync(esUrl, indexName, source.ToTypeKey(), mapping); } } }
private async Task SetupMappingsAsync(DiagnosticsSource source) { foreach (var indexName in source.GetIndexNames()) { var esUrl = _configurationValueProvider.GetValue(ConfigurationKeys.ElasticSearchUrl); await _elasticsearchClient.CreateIndexIfNotExistsAsync(esUrl, indexName); if (!await _elasticsearchClient.MappingExistsAsync(esUrl, indexName, source.ToTypeKey())) { var jsonPath = string.Format("{0}{1}.json", _configurationValueProvider.GetValue(ConfigurationKeys.MappingsPath), source.GetMappingName()); var client = new WebClient(); var mapping = client.DownloadString(jsonPath).Replace("___type_name___", source.ToTypeKey()); await _elasticsearchClient.UpdateMappingAsync(esUrl, indexName, source.ToTypeKey(), mapping); } } }
private async Task SetupMappingsAsync(DiagnosticsSource source) { foreach (var indexName in source.GetIndexNames()) { var esUrl = _configurationValueProvider.GetValue(ConfigurationKeys.ElasticSearchUrl); await _elasticsearchClient.CreateIndexIfNotExistsAsync(esUrl, indexName); if (!await _elasticsearchClient.MappingExistsAsync(esUrl, indexName, source.ToTypeKey())) { var jsonPath = string.Format("{0}{1}.json", _configurationValueProvider.GetValue(ConfigurationKeys.MappingsPath), source.GetMappingName()); var client = new WebClient(); var mapping = client.DownloadString(jsonPath).Replace("___type_name___", source.ToTypeKey()); await _elasticsearchClient.UpdateMappingAsync(esUrl, indexName, source.ToTypeKey(), mapping); } } }