ElasticSearch 5 – How to start using NEST C# .net

In this guide i want to show you how to start in c# .net framework with ElasticSearch version 5, with the library NEST.

WHAT IS ELASTICSEARCH 5

Elasticsearch is a Lucene-based search server with Full Text capability, with support for distributed architectures. All features are natively exposed through RESTful interface, while information is handled as JSON documents.
Is a database that contain many table and date, the table are called “index” and the date are called “documents” is like a no-sql database, as mongodb or couchbase.
In each “index” you can load many “documents” with many different “mapping”.

I suggest to install Kibana to manage ElasticSeach. Starter guide.

CHAPTER MAPPING LINK OFFICIAL DOC.

You can put the mapping on elastic search server throw Kibana dev console.
Mapping is the process of defining how a document, and the fields it contains, are stored and indexed. For instance, use mappings to define:

  • which string fields should be treated as full text fields.
  • which fields contain numbers, dates, or geolocations.
  • whether the values of all fields in the document should be indexed into the catch-all _allfield.
  • the format of date values.
  • custom rules to control the mapping for dynamically added fields.

In the mapping you can define the field, and each field as a datatype. Read the official guide for all datatypes.
Principles datatype:
– boolean
– int | short | long
– date
– text
– keyword
– specialized type (as IP, Completion (autocomplete), Token count datatype)

NEST C#

NEST is a high level client that has the advantage of having mapped all the request and response objects, comes with a strongly typed query DSL that maps 1 to 1 with the Elasticsearch query DSL, and takes advantage of specific .NET features such as covariant results and auto mapping of POCOs. NEST internally uses and still exposes the low level Elasticsearch.Net client.
Link to download NEST.

PRATICAL USE OF NEST C#

Now we must to create the filter query to take data.
Using Nest to take this is very simple, i show you an example:

Mapping of data type and method:
Boolean => Exists
Date => DateRange
Number => Range
Text Like => WildCard
Text Exact => Term

Now i’have used the Bool Query type, but exist other type, remind you to this official link.

USING NEST SCROLL

The scroll API allows you to efficiently page through a large dataset as it keeps the query alive in the cluster. And if you want all / unlimited data, without pagination.