Reputation: 301
I want to bulk index json records to elastic search with NEST or Elasticsearch.Net API
My json data is :
{"index":{"_index":"abc","_type":"abc","_id":1}},{"Name":"ApplicationFrameHost","CPU":1.25,"Company":null,"Product":null,"Path":null},{"index":{"_index":"abc","_type":"abc","_id":2}},{"Name":"Calculator","CPU":0.5,"Company":null,"Product":null,"Path":null},{"index":{"_index":"abc","_type":"abc","_id":3}},{"Name":"chrome","CPU":142.9375,"Company":null,"Product":null,"Path":null},{"index":{"_index":"abc","_type":"abc","_id":4}},{"Name":"chrome","CPU":3336.34375,"Company":null,"Product":null,"Path":null},{"index":{"_index":"abc","_type":"abc","_id":5}},{"Name":"chrome","CPU":7.1875,"Company":null,"Product":null,"Path":null}\n\n
my code:
var connectionSettings = new ConnectionSettings(new
Uri("http://localhost:9200/"));
var client2 = new ElasticClient(connectionSettings);
var jsonPostData = new PostData<object>(myJson);
var bulkRequestParameters = new BulkRequestParameters
{
};
Func<BulkRequestParameters, BulkRequestParameters> convert = delegate
(BulkRequestParameters s)
{
s.ErrorTrace(true);
return s.Refresh(Refresh.True);
};
var response = client2.LowLevel.Bulk<VoidResponse>("abc", "abc",
jsonPostData, convert);
In the response elastic return success with no error but still, data is not available on elastic?
Debug info from elastic:Successful low level call on POST: /abc/abc/_bulk?error_trace=true&refresh=true
It would be very helpful if someone can provide any clue what I am doing wrong here?
Upvotes: 1
Views: 1926
Reputation: 301
Solved this by modifying input JSON format after each record-set it does not requires comma:
{"index":{"_index":"abc","_type":"abc","_id":1}}{"Name":"ApplicationFrameHost","CPU":1.25,"Company":null,"Product":null,"Path":null}{"index":{"_index":"abc","_type":"abc","_id":2}},{"Name":"audiodg","CPU":1.5625,"Company":null,"Product":null,"Path":null}{"index":{"_index":"abc","_type":"abc","_id":3}},{"Name":"Calculator","CPU":0.5,"Company":null,"Product":null,"Path":null}{"index":{"_index":"abc","_type":"abc","_id":4}},{"Name":"chrome","CPU":144.109375,"Company":null,"Product":null,"Path":null}{"index":{"_index":"abc","_type":"abc","_id":5}},{"Name":"chrome","CPU":3384.609375,"Company":null,"Product":null,"Path":null}
Upvotes: 1