1

How Can I index json data using NEST?

If I try to index some data in JSON, it gives me the following error :

MapperParsingException[Malformed content, must start with an object]

I saw we can do this using PlainElastic.Net etc.

Is there a way of doing it in NEST?

1 Answer 1

3

Here's how to index a single post in NEST:

var post = new Post() { Id = 12, ... }
var status = client.Index<Post>(post);

Here's how to bulk index many docs:

var descriptor = new BulkDescriptor();
foreach (var i in Enumerable.Range(0, 1000))
    descriptor.Index<ElasticSearchProject>(op => op.Object(new ElasticSearchProject {Id = i}));

var result = this._client.Bulk(descriptor);

In the NEST docs, check out the Index and Bulk sections for more info.

Sign up to request clarification or add additional context in comments.

1 Comment

This works awesome. Just for reference, I tried to both ways on my laptop, with ~67,000 records. Indexing each one individually in a loop took around 35 seconds. Using Bulk with batches of 10,000 took about 7 seconds.

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.