How do i add documents to elasticsearch using NEST Bulk Api -
I have to index 5000 documents from the table below is the code that I use for bulk indexing.
Generate Public Action CreateBulk () {var descriptor = new bulk descriptor (); Foreach (db.Attendance.Take test on (5000) .toList ()) {discriptor.Index & LT; Appearance & gt; (Op = & gt; op.Document (new presence {AttendanceId = test.AttendanceId, AttendanceDate = test.AttendanceDate, Estates = test.Estate, Division = test.Division, FieldNo = test.FieldNo, employee = test.Employee, Activity = Test.Activity, volume = test.Quantity})); } Var bulkresult = Elastic client. Bullock (descriptor); Return Redirect Action ("Index"); }
But when I run the code, I am getting the following error:
System.NullReferenceException user code HRESULT = - + 2147467261 without message The verb = object is not set according to the frequency of the object. is. Source = Nest StackTrace: On the Nest.NestSerializer.SerializeBulkDescriptor (IBulkRequest bulkRequest) in: \ Users \ gmarz \ code \ elasticsearch Pure \ src \ nest \ ExposedInternals \ NestSerializer.cs:. Line 166 on the Nest.ElasticClient & lt; Bulk & gt; B__1b6 (ElasticsearchPathInfo`1p, BulkDescriptor d) in c: \ Users \ gmarz \ code \ elasticsearch pure \ src \ nest \ ElasticClient-Bulk.cs: line Nest.ElasticClient.Dispatch [D, Q, R] (31D descriptor) , Func`3 dispatch) C: \ Users \ gmarz \ code \ elasticsearch pure \ src \ nest \ ElasticClient.cs: Line Nest.ElasticClient.Dispatch [D, Q, R] (Func`2 selector at 82, Func in c `3 Send): \ Users \ gmarz \ code \ elasticsearch pure \ src \ nest \ ElasticClient.cs: In the line c. Nest.ElasticClient.Bulk (Func`2 bulkSelector) in 70: \ Users \ gmarz \ code \ elasticsearch \ Src \ nest \ ElasticClient-Bulk.cs: Line 27 AttendancePOC.Controllers.AttendanceController.CreateBulk () in D R: \ GIT source \ ElasticSearch \ AttendancePOC \ AttendancePOC \ controllers \ AttendanceController.cs: line 114 beat bda_method (off, ControllerBase,, [] object (), ControllerBase controller object [] parameters) System.Web.Mvc.ActionMethodDispatcher.Execute On System.Web.Mvc.ReflectedActionDescriptor.Execute on System (ControllerContext controllerContext, IDictionary`2 parameter) on System.Web.Mvc.Async.AsyncControllerActionInvoker Web.Mvc.ControllerActionInvoker.InvokeActionMethod (Controller Contact Controller Context, Action Descriptor Action Descriptor, IDictionary`2 parameters). & Lt; & Gt; C__DisplayClass42. & Lt; BeginInvokeSynchronousActionMethod & gt; B__41 () system at Web.Mvc .Senav Async Riserver. & Lt; & Gt; C__DisplayClass8`. & Lt; Initial Synchronous & gt; B__7 (IASINCRSlt_) on system. Web. MScAsININASSCINSRSDRAFRAPR.PRPADSINCRSelt` 1.and () on system. Web. Mssiassiansiasaiansikantrolrakshnincokr .EndInvokeActionMethod (IAsyncResult asyncResult) on System.Web.Mvc.Async.AsyncControllerActionInvoker. & Lt; & Gt; C__DisplayClass37 & lt; & Gt; .. C__DisplayClass39 & LT; In the system.WaveActionModewithFilter & gt; B__33 () System.Web.Mvc.Async.AsyncControllerActionInvoker. & Lt; & Gt; C__DisplayClass4f. & Lt; InvokeActionMethodFilter asynchronous & gt; b__49 () InnerException:
Please help me .. what is wrong in my code ?.
I had the same exact problem. I forgot to set the index name for this query I had set up a configuration that went to set a default index during the construction of new ElasticClient, but the configuration is changed and challenged my index. Hope that helps