コード例 #1
0
        public ElasticSerializationResult Serialize(IEnumerable <EntityContextInfo> entities)
        {
            if (entities == null)
            {
                return(null);
            }

            _elasticSerializationResult  = new ElasticSerializationResult();
            _elasticsearchCrudJsonWriter = new ElasticsearchCrudJsonWriter();

            foreach (var entity in entities)
            {
                string index = _elasticsearchSerializerConfiguration.ElasticsearchMappingResolver.GetElasticSearchMapping(entity.EntityType).GetIndexForType(entity.EntityType);
                MappingUtils.GuardAgainstBadIndexName(index);

                if (_saveChangesAndInitMappingsForChildDocuments)
                {
                    _indexMappings.CreateIndexSettingsAndMappingsForDocument(
                        index,
                        new IndexSettings {
                        NumberOfShards = 5, NumberOfReplicas = 1
                    },
                        new IndexAliases(),
                        new IndexWarmers(),
                        entity, new MappingDefinition {
                        Index = index
                    });
                }

                if (entity.DeleteDocument)
                {
                    DeleteEntity(entity);
                }
                else
                {
                    AddUpdateEntity(entity);
                }
            }

            _elasticsearchCrudJsonWriter.Dispose();
            _elasticSerializationResult.Content       = _elasticsearchCrudJsonWriter.Stringbuilder.ToString();
            _elasticSerializationResult.IndexMappings = _indexMappings;
            return(_elasticSerializationResult);
        }
コード例 #2
0
        public ElasticSerializationResult Serialize(IEnumerable<EntityContextInfo> entities)
        {
            if (entities == null)
            {
                return null;
            }

            _elasticSerializationResult = new ElasticSerializationResult();
            _elasticsearchCrudJsonWriter = new ElasticsearchCrudJsonWriter();

            foreach (var entity in entities)
            {
                string index = _elasticsearchSerializerConfiguration.ElasticsearchMappingResolver.GetElasticSearchMapping(entity.EntityType).GetIndexForType(entity.EntityType);
                MappingUtils.GuardAgainstBadIndexName(index);

                if (_saveChangesAndInitMappingsForChildDocuments)
                {
                    _indexMappings.CreateIndexSettingsForDocument(index, new IndexSettings{NumberOfShards=5,NumberOfReplicas=1}, new IndexAliases(), new IndexWarmers() );
                    _indexMappings.CreatePropertyMappingForTopDocument(entity, new MappingDefinition{Index=index});
                }

                if (entity.DeleteDocument)
                {
                    DeleteEntity(entity);
                }
                else
                {
                    AddUpdateEntity(entity);
                }
            }

            _elasticsearchCrudJsonWriter.Dispose();
            _elasticSerializationResult.Content = _elasticsearchCrudJsonWriter.Stringbuilder.ToString();
            _elasticSerializationResult.IndexMappings = _indexMappings;
            return _elasticSerializationResult;
        }
コード例 #3
0
 public void Dispose()
 {
     _elasticsearchCrudJsonWriter.Dispose();
 }