JURS
JURS

Reputation: 67

lock individual documents in elastic search using nest

I am looking for a good example to lock a document in elastic search. The below link explain how to do this in elasticsearch.

http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/concurrency-solutions.html

How can i achieve this using NEST. can someone suggest an approach to start with.

Upvotes: 2

Views: 1887

Answers (1)

Snixtor
Snixtor

Reputation: 4297

To start with, read the NEST Quick Start article. In particular, note the following:

NEST is a high level elasticsearch client that still maps very closely to the original elasticsearch API. Requests and Responses have been mapped to CLR objects and NEST also comes with a powerful strongly typed query dsl.

Consider also, that you may not require the added level of abstraction that NEST provides, and may prefer to directly utilise Elasticsearch.NET. Read also, it's own Quick Start article.

With that in mind, implementing the steps in the Solving concurrency issues article using NEST / Elasticsearch.NET is simply a matter of identifying the .NET methods that correspond to the necessary Elasticsearch API methods. The first one for example:

PUT /fs/lock/global/_create
{}

In NEST would look something like:

var createGlobalLockResponse = esClient.Index<object>(new object(), f => f
    .Index("fs")
    .Type("lock")
    .Id("global")
    .OpType(global::Elasticsearch.Net.OpType.Create));

Regarding the check of whether "this create request fails with a conflict exception", check the properties on the createGlobalLockResponse object. In particular, Created and if you're intending to get a bit more specific in the handling, ServerError.

Upvotes: 2

Related Questions