A
A
Artem2014-11-21 15:50:14
C++ / C#
Artem, 2014-11-21 15:50:14

Why is Bulk Insert not working in Elastic Search?

Hello!
I use Nest to communicate with ElasticSearch (I took Nest from the NuGet repositories). .NET Framework 4, x86. I'm trying to add a document using the Bulk method like this:

namespace NestTestCSharp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

        var client = new ElasticsearchClient();


        var p = new Phrase
        {
            Id = 1,
            Name = "скачать1"
        };


       var descriptor = new BulkDescriptor();

        descriptor.Index<Phrase>(op => op
            .Document(p)
        );

        
        var index = client.Bulk("phrases", "phrase", descriptor);

        }
    }

    class Phrase
    {
        public long Id { get; set; }
        public string Name { get; set; }
    }
}

I get an empty Request and a response like:
{StatusCode: 400, 
  Method: POST, 
  Url: http://localhost:9200/phrases/phrase/_bulk, 
  Request: {}, 
  Response: <Response stream not captured or already read to completion by serializer>
  ExceptionMessage: Validation Failed: 1: no requests added;
   StackTrace: }

Tell me what could be the problem? The code is copied from the official source with minimal changes. I twisted it in every way, but I just can’t add data in batches. Data one by one through client.Index is added normally.
PS I tried, including in this way:
var request = new BulkRequest()
        {
            Refresh = true,
            Consistency = Consistency.One,
            Operations = new List<IBulkOperation>
    {
        { new BulkIndexOperation<Phrase>(p) { Id= "1"} }
   }
        };

        var response = client.Bulk(request);

An error is thrown:
Метод может быть вызван только для метода, для которого значение Type.IsGenericParameter является true.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question