コード例 #1
0
 public ElasticsearchSerializer(ITraceProvider traceProvider, ElasticsearchSerializerConfiguration elasticsearchSerializerConfiguration, bool saveChangesAndInitMappingsForChildDocuments)
 {
     _elasticsearchSerializerConfiguration        = elasticsearchSerializerConfiguration;
     _saveChangesAndInitMappingsForChildDocuments = saveChangesAndInitMappingsForChildDocuments;
     _traceProvider = traceProvider;
     _indexMappings = new IndexMappings(_traceProvider, _elasticsearchSerializerConfiguration);
     _elasticSerializationResult.IndexMappings = _indexMappings;
 }
コード例 #2
0
 public ElasticsearchSerializer(ITraceProvider traceProvider, ElasticsearchSerializerConfiguration elasticsearchSerializerConfiguration, bool saveChangesAndInitMappingsForChildDocuments)
 {
     _elasticsearchSerializerConfiguration = elasticsearchSerializerConfiguration;
     _saveChangesAndInitMappingsForChildDocuments = saveChangesAndInitMappingsForChildDocuments;
     _traceProvider = traceProvider;
     _indexMappings = new IndexMappings(_traceProvider, _elasticsearchSerializerConfiguration);
     _elasticSerializationResult.IndexMappings = _indexMappings;
 }
コード例 #3
0
        public async Task <ResultDetails <string> > CreateIndexWithMappingAsync <T>(IndexDefinition indexDefinition)
        {
            if (indexDefinition == null)
            {
                indexDefinition = new IndexDefinition();
            }
            _traceProvider.Trace(TraceEventType.Verbose, "{0}: CreateIndexWithMappingAsync Elasticsearch started", "ElasticsearchContextIndexMapping");
            var resultDetails = new ResultDetails <string> {
                Status = HttpStatusCode.InternalServerError
            };

            try
            {
                var item = Activator.CreateInstance <T>();
                var entityContextInfo = new EntityContextInfo
                {
                    RoutingDefinition = indexDefinition.Mapping.RoutingDefinition,
                    Document          = item,
                    EntityType        = typeof(T),
                    Id = "0"
                };

                string index =
                    _elasticsearchSerializerConfiguration.ElasticsearchMappingResolver.GetElasticSearchMapping(
                        entityContextInfo.EntityType).GetIndexForType(entityContextInfo.EntityType);
                MappingUtils.GuardAgainstBadIndexName(index);

                var indexMappings = new IndexMappings(_traceProvider, _elasticsearchSerializerConfiguration);
                indexMappings.CreateIndexSettingsAndMappingsForDocument(
                    index,
                    indexDefinition.IndexSettings,
                    indexDefinition.IndexAliases,
                    indexDefinition.IndexWarmers, entityContextInfo, indexDefinition.Mapping);
                indexDefinition.Mapping.Index = index;
                //indexMappings.CreatePropertyMappingForTopDocument(entityContextInfo, indexDefinition.Mapping);
                await indexMappings.Execute(_client, _connectionString, _traceProvider, _cancellationTokenSource);

                return(resultDetails);
            }
            catch (OperationCanceledException oex)
            {
                _traceProvider.Trace(TraceEventType.Warning, oex, "{1}: CreateIndexWithMappingAsync Request OperationCanceledException: {0}", oex.Message,
                                     "ElasticsearchContextIndexMapping");
                resultDetails.Description = "OperationCanceledException";
                return(resultDetails);
            }
        }
コード例 #4
0
        public async Task <ResultDetails <string> > CreateIndexAsync(string index, IndexSettings indexSettings, IndexAliases indexAliases, IndexWarmers indexWarmers)
        {
            if (string.IsNullOrEmpty(index))
            {
                throw new ElasticsearchCrudException("CreateIndexAsync: index is required");
            }
            if (indexSettings == null)
            {
                indexSettings = new IndexSettings {
                    NumberOfShards = 5, NumberOfReplicas = 1
                };
            }
            if (indexAliases == null)
            {
                indexAliases = new IndexAliases();
            }

            if (indexWarmers == null)
            {
                indexWarmers = new IndexWarmers();
            }

            _traceProvider.Trace(TraceEventType.Verbose, "{0}: CreateIndexAsync Elasticsearch started", "ElasticsearchContextIndexMapping");
            var resultDetails = new ResultDetails <string> {
                Status = HttpStatusCode.InternalServerError
            };

            try
            {
                MappingUtils.GuardAgainstBadIndexName(index);

                var indexMappings = new IndexMappings(_traceProvider, _elasticsearchSerializerConfiguration);
                indexMappings.CreateIndexSettingsForDocument(index, indexSettings, indexAliases, indexWarmers);
                await indexMappings.Execute(_client, _connectionString, _traceProvider, _cancellationTokenSource);

                return(resultDetails);
            }
            catch (OperationCanceledException oex)
            {
                _traceProvider.Trace(TraceEventType.Warning, oex, "{1}: CreateIndexAsync Request OperationCanceledException: {0}", oex.Message,
                                     "ElasticsearchContextIndexMapping");
                resultDetails.Description = "OperationCanceledException";
                return(resultDetails);
            }
        }
コード例 #5
0
        public async Task <ResultDetails <string> > CreateTypeMappingForIndexAsync <T>(MappingDefinition mappingDefinition)
        {
            if (mappingDefinition == null)
            {
                throw new ElasticsearchCrudException("CreateTypeMappingForIndexAsync: A mapping definition with the parent index is required");
            }
            _traceProvider.Trace(TraceEventType.Verbose, "{0}: CreateTypeMappingForIndex Elasticsearch started", "ElasticsearchContextIndexMapping");
            var resultDetails = new ResultDetails <string> {
                Status = HttpStatusCode.InternalServerError
            };

            try
            {
                var indexMappings = new IndexMappings(_traceProvider, _elasticsearchSerializerConfiguration);

                var item = Activator.CreateInstance <T>();

                var entityContextInfo = new EntityContextInfo
                {
                    RoutingDefinition = mappingDefinition.RoutingDefinition,
                    Document          = item,
                    EntityType        = typeof(T),
                    Id = "0"
                };

                if (string.IsNullOrEmpty(mappingDefinition.Index))
                {
                    string index = _elasticsearchSerializerConfiguration.ElasticsearchMappingResolver.GetElasticSearchMapping(entityContextInfo.EntityType).GetIndexForType(entityContextInfo.EntityType);
                    MappingUtils.GuardAgainstBadIndexName(index);
                    mappingDefinition.Index = index;
                }

                indexMappings.CreatePropertyMappingForTopDocument(entityContextInfo, mappingDefinition);
                await indexMappings.Execute(_client, _connectionString, _traceProvider, _cancellationTokenSource);

                return(resultDetails);
            }
            catch (OperationCanceledException oex)
            {
                _traceProvider.Trace(TraceEventType.Warning, oex, "{1}: CreateTypeMappingForIndexAsync Request OperationCanceledException: {0}", oex.Message,
                                     "ElasticsearchContextIndexMapping");
                resultDetails.Description = "OperationCanceledException";
                return(resultDetails);
            }
        }
コード例 #6
0
        public async Task <ResultDetails <string> > UpdateIndexSettingsAsync(IndexUpdateSettings indexUpdateSettings, string index = null)
        {
            _traceProvider.Trace(TraceEventType.Verbose, "{0}: UpdateIndexSettingsAsync Elasticsearch started", "ElasticsearchContextIndexMapping");
            var resultDetails = new ResultDetails <string> {
                Status = HttpStatusCode.InternalServerError
            };

            try
            {
                var indexMappings = new IndexMappings(_traceProvider, _elasticsearchSerializerConfiguration);
                indexMappings.UpdateSettings(index, indexUpdateSettings);
                await indexMappings.Execute(_client, _connectionString, _traceProvider, _cancellationTokenSource);

                resultDetails.PayloadResult = "completed";
                return(resultDetails);
            }
            catch (OperationCanceledException oex)
            {
                _traceProvider.Trace(TraceEventType.Warning, oex, "{1}: UpdateIndexSettingsAsync OperationCanceledException: {0}", oex.Message,
                                     "ElasticsearchContextIndexMapping");
                resultDetails.Description = "OperationCanceledException";
                return(resultDetails);
            }
        }