9

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?
4
  • 1
    why not using IndexMany? Commented Jun 4, 2015 at 11:33
  • 2
    thanx. I now have: SPl.Select(I => Client.IndexMany(I, "products")) And it works. But: IndexId is my id for the product. How do i tell Elasticsearch to use this id? Or must i specify a id? Commented Jun 5, 2015 at 7:03
  • 1
    Rename the IndexId field to Id and elasticsearch will use this by convention as the id of the document. Commented Jun 5, 2015 at 7:06
  • @mrcode : see my answer below and mark it if its helpful Commented Jun 5, 2015 at 10:39

1 Answer 1

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>")]
Sign up to request clarification or add additional context in comments.

2 Comments

Perfect. Is there a easy way to mark wich properties i dont want to index in elasticsearch? :)
@mrcode : yes , please go through the answer stackoverflow.com/questions/23063839/…. mark the above answer if it is correct

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.