Esempio n. 1
0
 private static IEnumerable <Func <object> > DocumentCommandsAsync(IElasticClient elastic)
 {
     return(new List <Func <object> >
     {
         () => elastic.BulkAsync(
             new BulkRequest("test_index")
         {
             Operations = new List <IBulkOperation>
             {
                 new BulkCreateOperation <Post>(new Post {
                     Id = 1, Title = "BulkCreateOperation"
                 })
             }
         }),
         () => elastic.CreateAsync(new CreateRequest <Post>(new Post {
             Id = 2, Title = "CreateRequest"
         }, "test_index")),
         () => elastic.CreateDocumentAsync(new Post {
             Id = 3, Title = "CreateDocument"
         }),
         () => elastic.CountAsync <Post>(),
         () => elastic.SearchAsync <Post>(s => s.MatchAll()),
         () => elastic.DeleteByQueryAsync(new DeleteByQueryRequest("test_index")
         {
             Size = 0
         })
     });
 }
        public async Task InsertDocument(string indexName, Product product)
        {
            var response = await _client.CreateAsync(product, q => q.Index(indexName));

            if (response.ApiCall?.HttpStatusCode == 409)
            {
                await _client.UpdateAsync <Product>(response.Id, a => a.Index(indexName).Doc(product));
            }
        }
Esempio n. 3
0
        public async Task <Book> Create(Book entity)
        {
            var response = await _client.CreateAsync(
                entity,
                s => s
                );

            if (!response.IsValid)
            {
                throw new Exception(response.DebugInformation, response.OriginalException);
            }

            // @TODO:
            // - Check how to get newly created ebook
            return(entity);
        }
        public async Task <IActionResult> IndexDocumentWithId([FromBody] Company companyData)
        {
            try
            {
                /// this will create document and if id is already there then throws a error
                /// id is mandatory in this scenario. it can be with the document or can be passed in request.
                var addNewIndex = await _elasticClient.CreateAsync(companyData, i => i.Index(IndexName).Id(Guid.NewGuid()));

                if (addNewIndex.IsValid)
                {
                    return(Ok(addNewIndex.Id));
                }
                else
                {
                    return(BadRequest(addNewIndex.ServerError.Error));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }