ElasticSearch C# NEST - How to prevent overwriting a document
Solution 1:
You can achieve this by using the _create
endpoint, or by specifying OpType.Create
when indexing the document
var client = new ElasticClient();
// using OpType.Create
client.Index(new Test { Id = 1, Message = "message 1" }, i => i
.OpType(OpType.Create)
);
// using _create endpoint
client.Create(new Test { Id = 1, Message = "message 1" });
If the document already exists, a HTTP 409 Conflict response will be returned. In both cases, you need an ID for the document that you're indexing/creating.