I am building an API application that essentially allows a user to build a document, which can be structured however they want, that will be stored in Elasticsearch. Essenti
Trying to index the document as type dynamic won't work, but you can index it as an object through the IndexRequest object.
dynamic dynamicDoc = new { /*fill in document format here*/ };
ElasticClient esClient = new ElasticClient(esSettings);
IndexRequest
Or if dealing with documents in bulk
List Documents = new List();
//Populate Documents
BulkDescriptor descriptor = new BulkDescriptor();
foreach(var doc in Documents)
{
descriptor.Index(i => i
.Index("someindex")
.Type("SomeType")
.Id("someid")
.Document(doc));
}
esClient.Bulk(descriptor);
NEST (or more accurately, Elasticsearch.Net) also has a .Raw method variant attached to the ElasticClient class, which can index raw JSON. Using Raw.Index() let's us do things like this:
The type descriptor for the response is the type you'll expect the response to be in (string means you'll have a serialized json response which you can deserialize and do something with). This allows us to sidestep the entire object type issue and NEST indexes the document into Elasticsearch exactly as expected.