public ElasticsearchClientFactory(IConfigurationService configurationService, ILogService logService) { var elasticsearchConfiguration = configurationService.Get <SearchConfiguration>(); foreach (var index in elasticsearchConfiguration.Indexes) { var mappingType = Type.GetType(index.MappingType); if (mappingType == null) { var error = string.Format("Mapping type not not valid: {0}", index.MappingType); logService.Error(error); throw new ArgumentException(error); } _typeIndexNameMap.Add(mappingType, index.Name); _documentTypeNameMap.Add(mappingType, ((ElasticTypeAttribute) mappingType.GetCustomAttributes(typeof(ElasticTypeAttribute), false) .First()).Name); } _connectionSettings = new ConnectionSettings(new Uri(elasticsearchConfiguration.HostName)); _connectionSettings.AddContractJsonConverters(t => typeof(Enum).IsAssignableFrom(t) ? new StringEnumConverter() : null); }
public ElasticsearchClientFactory(ElasticsearchConfiguration elasticsearchConfiguration, bool buildIndexes = true) { _elasticsearchConfiguration = elasticsearchConfiguration; _elasticsearchConfiguration.Indexes.ToList().ForEach(idx => _typeIndexNameMap.Add(idx.MappingType, idx.Name)); _elasticsearchConfiguration.Indexes.ToList() .ForEach( idx => _documentTypeNameMap.Add(idx.MappingType, ((ElasticTypeAttribute) idx.MappingType.GetCustomAttributes(typeof(ElasticTypeAttribute), false) .FirstOrDefault()).Name)); _connectionSettings = new ConnectionSettings(_elasticsearchConfiguration.DefaultHost); _connectionSettings.AddContractJsonConverters(t => typeof(Enum).IsAssignableFrom(t) ? new StringEnumConverter() : null); }