public void PostArticlesSample()
        {
            if (!_elasticClient.Indices.Exists(IndexArticles.ArticleIndex).Exists)
            {
                _elasticClient.Indices.Create(IndexArticles.ArticleIndex);
            }

            _elasticClient.IndexMany <IndexArticles>(IndexArticles.GetSampleData(), IndexArticles.ArticleIndex);

            #region
            var descriptor = new BulkDescriptor();

            descriptor.UpdateMany <IndexArticles>(IndexArticles.GetSampleData(), (b, u) => b
                                                  .Index(IndexArticles.ArticleIndex)
                                                  .Doc(u)
                                                  .DocAsUpsert());

            var insert = _elasticClient.Bulk(descriptor);

            if (!insert.IsValid)
            {
                throw new Exception(insert.OriginalException.ToString());
            }
            #endregion
        }
Exemple #2
0
        public void Add()
        {
            BulkDescriptor bulkDescriptor = new BulkDescriptor();

            bulkDescriptor.UpdateMany <IndexItem>(GetSampleData(), (b, u) =>
                                                  b.Index(_indexName)
                                                  .Doc(u)
                                                  .DocAsUpsert());

            BulkResponse insert = _elasticClient.Bulk(bulkDescriptor);

            if (insert.IsValid is false)
            {
                throw new Exception(insert.OriginalException.ToString());
            }
        }
Exemple #3
0
        public void PostCatalogsSample()
        {
            if (!_elasticClient.Indices.Exists(nameof(IndexCatalog).ToLower()).Exists)
            {
                _elasticClient.Indices.Create(nameof(IndexCatalog).ToLower());
            }

            _elasticClient.IndexMany <IndexCatalog>(IndexCatalog.GetCatalog());

            var descriptor = new BulkDescriptor();

            descriptor.UpdateMany <IndexCatalog>(IndexCatalog.GetCatalog(), (b, u) => b
                                                 .Index(nameof(IndexCatalog).ToLower())
                                                 .Doc(u)
                                                 .DocAsUpsert());

            var insert = _elasticClient.Bulk(descriptor);

            if (!insert.IsValid)
            {
                throw new Exception(insert.OriginalException.ToString());
            }
        }
Exemple #4
0
        public void PostLogsSample()
        {
            try
            {
                var descriptor = new BulkDescriptor();

                descriptor.UpdateMany(IndexLog.GetSampleData(), (b, u) => b
                                      .Index($"{_elasticIndex}-{DateTime.Now:yyyy.MM.dd}")
                                      .Doc(u)
                                      .DocAsUpsert());

                var insert = _elasticClient.Bulk(descriptor);

                if (!insert.IsValid)
                {
                    throw new Exception(insert.OriginalException.ToString());
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemple #5
0
    public void PostSampleElastic()
    {
        var descriptor = new BulkDescriptor();

        if (!_elasticClient.Indices.Exists(nameof(IndexActorsModel).ToLower()).Exists)
        {
            _elasticClient.Indices.Create(nameof(IndexActorsModel).ToLower());
        }

        _elasticClient.IndexMany(IndexActorsModel.GetSampleData());

        //or
        descriptor.UpdateMany <IndexActorsModel>(IndexActorsModel.GetSampleData(), (b, u) => b
                                                 .Index(nameof(IndexActorsModel).ToLower())
                                                 .Doc(u)
                                                 .DocAsUpsert());

        var insert = _elasticClient.Bulk(descriptor);

        if (!insert.IsValid)
        {
            throw new Exception(insert.OriginalException.ToString());
        }
    }