8

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

My code:

        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,

  1. Where can i set the name of the index?
  2. Why did i get, Validation Failed: 1: no requests added;?
  3. IndexId is my id for the product. How do i tell Elasticsearch to use this id? Or must i specify a id?
mrcode
  • 465
  • 2
  • 5
  • 16

1 Answers1

7

Refering to your previous problem, you can use IndexMany for indexing the data. Now as per your question in comment, you can specify the id which elastic search will use. see the below example.

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

if you dont want to specify any Id to elastic search, create a dummy field dummyId(nullable) and put it in "IdProperty". Elastic search will auto assign the value to it if it null.

Edit : From 2.3 onwards, Its

[ElasticsearchType(IdProperty = "<fieldName>")]
Shivang MIttal
  • 990
  • 1
  • 14
  • 36
  • Perfect. Is there a easy way to mark wich properties i dont want to index in elasticsearch? :) – mrcode Jun 05 '15 at 21:49
  • 1
    @mrcode : yes , please go through the answer http://stackoverflow.com/questions/23063839/c-sharp-nest-elasticsearch-exclude-object-property-from-being-indexed. mark the above answer if it is correct – Shivang MIttal Jun 07 '15 at 17:17