Bulk insert in ElasticSearch using NEST

I am trying to add 100k products to elasticsearch, but when I try to get: {"Validation error: 1: no requests added;" }

My code is:

var Node = new Uri("......"); var ConnectionPool = new SniffingConnectionPool(new[] { Node }); var Config = new ConnectionConfiguration(ConnectionPool) .SniffOnConnectionFault(false) .SniffOnStartup(false) .SniffLifeSpan(TimeSpan.FromMinutes(10)); var Client = new ElasticsearchClient(Config); var AllProducts = Product.GetProducts(); var SPl = AllProducts.Split(100); // Split into 100 collections/requests var COll = new List<ElasticsearchResponse<DynamicDictionary>>(); foreach (var I in SPl) { var Descriptor = new BulkDescriptor(); foreach (var Product in I) { Descriptor.Index<Product>(op => op.Document(Product)); } COll.Add(Client.Bulk(Descriptor)); } 

AllProducts contains a list of this object:

 public class Product { public int AffiliateNr { get; set; } public string AffiliateProductId { get; set; } public int BrandNr { get; set; } public string Currency { get; set; } public string IndexId { get; set; } public decimal Price { get; set; } public long ProductNr { get; set; } public string Title { get; set; } } 

So,

  • Where can I set the index name?
  • Why did I get Validation Failed: 1: no requests were added ;?
  • IndexId is my product identifier. How can I tell Elasticsearch to use this identifier? Or should I specify an identifier?
+6
source share
1 answer

Referring to your previous problem, you can use IndexMany to index data. Now, according to your question in the comment, you can specify an identifier that elastic search will use. see the example below.

  ElasticType(IdProperty = "<fieldName>")] public class ClassName { 

if you do not want to specify any identifier for the elastic image search, create a dummyId dummy field (NULL value) and put it in "IdProperty". Elastic search automatically assigns a value to it if it is null.

Edit: Starting with version 2.3,

 [ElasticsearchType(IdProperty = "<fieldName>")] 
+5
source

Source: https://habr.com/ru/post/988505/


All Articles