Health
+ +cluster health has not yet been mapped
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
diff --git a/cluster/health.html b/cluster/health.html new file mode 100644 index 00000000000..72af991c4f5 --- /dev/null +++ b/cluster/health.html @@ -0,0 +1,99 @@ + + + + +
+cluster health has not yet been mapped
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
Nodes info has not yet been mapped
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
nodes shutdown has not yet been mapped
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
Nodes stats has not yet been mapped
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
cluster state has not yet been mapped
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
cluster settings have not yet been mapped
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
This section describes how to instantiate a client and have it connect to the server.
+ +var elasticSettings = new ConnectionSettings("127.0.0.1.", 9200)
+ .SetDefaultIndex("mpdreamz");
+var client = new ElasticClient(elasticSettings);
+
+
+ConnectionSettings
's constructor has many overloads, including support for connecting through proxies.
Connecting can be done several ways:
+ +ConnectionStatus connectionStatus;
+if (client.TryConnect(out connectionStatus))
+
+
+Or if you don't care about error reasons
+ +if (client.IsValid)
+
+
+both will perform a one time lookup to see if ElasticSearch is available and ready.
+ +Settings can be set in a fluent fashion: new ConnectionSettings().SetDefaultIndex().SetMaximumConnections()
Calling SetDefaultIndex()
on ConnectionSettings
will set the default index for the client. Whenever a method is called that doesn't explicitly passes an index this default will be used.
Calling SetMaximumAsyncConnections()
on ConnectionSettings
will set the maximum async connections the client will send to ElasticSearch at the same time. If the maximum is hit the calls will be queued untill a slot becomes available.
You can pass a Func<string,string>
to SetTypeNameInferrer()on
ConnectionSettings` to overide NEST's default behavior of lowercasing and pluralizing typenames.
Setting UsePrettyResponses()
on ConnectionSettings
will append pretty=true
to all the requests to inform ElasticSearch we want nicely formatted responses, setting this does not prettify requests themselves because bulk requests in ElasticSearch follow a very exact line delimited format.
+ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
All responses have the following properties
+ +IsValid
and ConnectionStatus
These properties pertain to NEST and whether NEST thinks the response is valid or not. In some cases though elasticsearch responds back with with an ok
or acknowledged
properties. NEST will always map these fields but they will not influence the IsValid
property. If NEST was successful in connecting and getting back a 200 status IsValid
will always be true by design. If you need to check for elasticsearch validity check the OK
or Acknowledged
properties where these apply.
ConnectionStatus
holds the HttpStatusCode and various other interesting information in case a transport error occurred.
NOTE in most cases elasticsearch will throw a 500 and in that case IsValid
will be false too. ConnectionStatus.Result
will hold the error message as recieved from elasticsearch.
+ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
This is sadly still a marker file.
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
This is sadly still a marker file.
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
This is sadly still a marker file.
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
this.ConnectedClient.DeleteByQuery<ElasticSearchProject>(q => q.Term(f => f.Name, "elasticsearch.pm"));
+
+
+Elasticsearch allows you to delete over multiple types and indexes, so does NEST.
+ +this.ConnectedClient.DeleteByQuery<ElasticSearchProject>(q => q
+ .Indices(new[] { "index1", "index2" })
+ .Term(f => f.Name, "elasticsearch.pm")
+);
+
+
+As always *Async
variants are available too.
You can also delete by query over all the indexes and types:
+ +this.ConnectedClient.DeleteByQuery<ElasticSearchProject>(q => q
+ .AllIndices()
+ .Term(f => f.Name, "elasticsearch.pm")
+);
+
+
+The DeleteByQuery can be further controlled by passing a DeleteByQueryParameters
object
this.ConnectedClient.DeleteByQuery<ElasticSearchProject>(
+ q => q.Term(f => f.Name, "elasticsearch.pm")
+ , new DeleteByQueryParameters { Consistency = Consistency.Quorum, Replication = Replication.Sync, Routing = "NEST" }
+);
+
+
+
+ + Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
The delete API allows to delete a typed JSON document from a specific index based on its id. See also deleting by query for other ways to delete data.
+ + this.ConnectedClient.DeleteById<ElasticSearchProject>(searchProject.Id);
+ this.ConnectedClient.DeleteByIdAsync<ElasticSearchProject>(searchProject.Id, c => /* called later */);
+
+
+Id property is inferred (can be any value type (int, string, float ...))
+ + this.ConnectedClient.Delete(searchProject);
+ this.ConnectedClient.DeleteAsync(searchProject);
+
+
+ this.ConnectedClient.Delete(searchProjects);
+ this.ConnectedClient.DeleteAsync(searchProjects);
+
+
+Using bulk parameters you can control the deletion of each individual document further
+ + var bulkedProjects = searchProjects
+ .Select(d=> new BulkParameters<ElasticSearchProject>(d)
+ {
+ Version = d.Version,
+ VersionType = VersionType.External
+ }
+ );
+ this.ConnectedClient.Delete(bulkedProjects, new SimpleBulkParameters() { Refresh = true });
+
+
+Please see deleting by query
+ +Please see delete mapping
+ +and delete index
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
gets a single document from Elasticsearch
+ +var foundDocument = this.ConnectedClient.Get<ElasticSearchProject>(hit.Id);
+
+
+index and type are infered but overloads exists for full control
+ +var foundDocument = this.ConnectedClient.Get<ElasticSearchProject>("myalternateindex", "elasticprojs", hit.Id);
+
+
+
+ + Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
Indexing is as simple as:
+ +var post = new Post() { Id = 12, ... }
+var status = client.Index<Post>(post);
+
+
+of course C# is smart enough to infer Post so
+ +var status = client.Index(post);
+
+
+is sufficient. this will index post too /[default index]/posts/12
. The typenameposts
is automatically inferred from the type.
if you need more control there are plenty of overloads, i.e:
+ +client.Index(post, "index", "type", "id");
+
+
+Indexing asynchronously is as easy as:
+ +//IndexAsync returns a Task<ConnectionStatus>
+var task = client.IndexAsync(post);
+
+
+You can pass aditional data using IndexParameters
client.Index(post, new IndexParameters() { VersionType = VersionType.External, Version = "212" });
+
+
+Similarly to force a wait for a refresh
+ +client.Index(post, new IndexParameters() { Refresh = true });
+
+
+Instead of passing T
just pass IEnumerable<T>
for both Index()
or IndexAsync()
. A zero copy approach that writes directly on the post stream is planned in a later version.
Note +For asynchronous commands there's a special connection setting which automatically semaphores threaded communication +to ES for you:
+ +var elasticSettings = new ConnectionSettings("127.0.0.1.", 9200)
+ .SetDefaultIndex("mpdreamz")
+ .SetMaximumAsyncConnections(20);
+
+
+this ensures that at most there are 20 asynchronous connections to ES others are enqueued until a slot is +available.
+ +Like the overloads just taking a T
the IEnumerable<T>
has alot of overloads taking in extra parameters.
client.Index(posts, new SimpleBulkParameters() { Refresh = true });
+
+
+The reason the IEnumerable<T>
overloads take a SimpleBulkParameters
is because to pass item specific parameters you'll have to wrap posts
in a BulkParameters<T>
i.e:
client.Index(posts.Select(p=>new BulkParameters<T>(p) { Version = p.Version }));
+
+
+This will do a bulk index on posts but use each individual posts version. Again there's plenty of overloads to mix and match:
+ +var bulkParams = posts.Select(p=>new BulkParameters<T>(p) { Version = p.Version });
+client.Index(bulkParams , new SimpleBulkParameters() { Refresh = true });
+
+
+
+ + Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
This is sadly still a marker file.
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
Get multiple documents in a single request.
+ +var ids = new [] { hit1.Id, hit2.Id };
+var foundDocuments = this.ConnectedClient.Get<ElasticSearchProject>(ids);
+
+
+index and type are infered but overloads exists for full control
+ +var foundDocuments = this.ConnectedClient.Get<ElasticSearchProject>("myalternateindex", "elasticprojs", ids);
+
+
+
+ + Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
This is sadly still a marker file.
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
This is sadly still a marker file.
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
This is sadly still a marker file.
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
The update API allows to update a document based on a script provided. The operation gets the document (collocated with the shard) from the index, runs the script (with optional script language and parameters), and index back the result (also allows to delete, or ignore the operation). It uses versioning to make sure no updates have happened during the “get” and “reindex”. (available from 0.19
onwards).
this.ConnectedClient.Update<ElasticSearchProject>(u => u
+ .Object(project)
+ .Script("ctx._source.loc += 10")
+ .RetriesOnConflict(5)
+ .Refresh()
+);
+
+
+This is just a simple example all the options that are available (such as passing params) are available.
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
A specific histogram facet that can work with date field types enhancing it over the regular histogram facet. Here is a quick example:
+ +this.ConnectedClient.Search<ElasticSearchProject>(s=>s
+ .From(0)
+ .Size(10)
+ .MatchAll()
+ .FacetDateHistogram(h => h
+ .OnField(f => f.StartedOn)
+ .Interval(DateInterval.Day)
+ .Factor(1000)
+ )
+);
+
+
+See original docs for more information
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
A filter facet (not to be confused with a facet filter) allows you to return a count of the hits matching the filter. The filter itself can be expressed using the Query DSL. For example:
+ +this.ConnectedClient.Search<ElasticSearchProject>(s=>s
+ .From(0)
+ .Size(10)
+ .MatchAll()
+ .FacetFilter("wow_facet", filter=>filter
+ .Exists(f=>f.Name)
+ )
+);
+
+
+See original docs for more information
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
The geodistance facet is a facet providing information for ranges of distances from a provided geopoint including count of the number of hits that fall within each range, and aggregation information (like total).
+ +this.ConnectedClient.Search<ElasticSearchProject>(s=>s
+ .From(0)
+ .Size(10)
+ .MatchAll()
+ .FacetGeoDistance("geo1", gd => gd
+ .OnValueField(f=>f.Origin)
+ .PinTo(Lat: 40, Lon: -70)
+ .Ranges(
+ r=>r.To(10),
+ r=>r.From(10).To(20),
+ r=>r.From(20).To(100),
+ r=>r.From(100)
+ )
+ )
+);
+
+
+See original docs for more information
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
For a good overview of what facets are see the original docs on the subject.
+ +In its simplest form you can add a facet to your query like this:
+ +var queryResults = this.ConnectedClient.Search<ElasticSearchProject>(s=>s
+ .From(0)
+ .Size(10)
+ .MatchAll()
+ .FacetTerm(t => t
+ .OnField(f => f.Country)
+ .Size(20)
+ )
+);
+
+
+Adding more then one facet is also really easy:
+ +var queryResults = this.ConnectedClient.Search<ElasticSearchProject>(s=>s
+ .From(0)
+ .Size(10)
+ .MatchAll()
+ .FacetTerm(t => t
+ .OnField(f => f.Country)
+ .Size(20)
+ )
+ .FacetTerm(t => t
+ .OnField(f => f.Author)
+ .Size(20)
+ )
+);
+
+
+Nest supports all the additional properties you can set on facets
+ +var queryResults = this.ConnectedClient.Search<ElasticSearchProject>(s=>s
+ .From(0)
+ .Size(10)
+ .MatchAll()
+ .FacetTerm(t => t
+ .OnField(f => f.Country)
+ .Size(20)
+ .Order(TermsOrder.reverse_count)
+ .Exclude("term1", "term2")
+ .AllTerms()
+ .Regex(@"\s+", RegexFlags.DOTALL)
+ .Script("term + 'aaa'")
+ .ScriptField("_source.my_field")
+ )
+ .FacetDateHistogram(h => h
+ .OnField(f => f.StartedOn)
+ .Interval(DateInterval.Day, DateRounding.Half_Floor)
+ .TimeZones(Pre: "-3", Post: "-4")
+ )
+);
+
+
+Allowing you to take advantage of all the cool facets stuff built in to elasticsearch.
+ +If you are interested in the facet meta data (such as missing, total) you can use the following methods:
+ +var facet = queryResults.Facet<TermFacet>(p=>p.Followers.Select(f=>f.LastName));
+
+
+this will return a TermFacet
object which has an .Items
property holding all the facets.
queryResult
also holds a .Facets
dictionary one can use to itterate over the facets returned from the query.
To get the facet items for followers.lastName
the prettiest way to get them is.
var facets = queryResults.FacetItems<FacetItem>(p=>p.Followers.Select(f=>f.LastName));
+
+
+NEST will infer the right key from the specified lambda. You can also opt for specifying the name directly.
+ +var facets = queryResults.FacetItems<FacetItem>("followers.lastName");
+
+
+NOTE more types then just term facets are supported see the 'Corresponding Types' section
+ +The following lists the elasticsearch facet type and their corresponding NEST strongly typed class
+ +terms_stats => TermStatsFacet
+ +statistical => StatisticalFacet
+ +terms => TermFacet
+ +histogram => HistogramFacet
+ +date_histogram => DateHistogramFacet
+ +range => DateRangeFacet, RangeFacet
+ +geo_distance => GeoDistanceFacet
+ +query => QueryFacet
+ +filter => FilterFacet
+ +See also each individual facet's documentation
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
The histogram facet works with numeric data by building a histogram across intervals of the field values. Each value is “rounded” into an interval (or placed in a bucket), and statistics are provided per interval/bucket (count and total). Here is a simple example:
+ +this.ConnectedClient.Search<ElasticSearchProject>(s=>s
+ .From(0)
+ .Size(10)
+ .MatchAll()
+ .FacetHistogram(h => h.OnField(f=>f.LOC).Interval(100))
+);
+
+
+See original docs for more information
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
A facet query allows to return a count of the hits matching the facet query. The query itself can be expressed using the Query DSL. For example:
+ +this.ConnectedClient.Search<ElasticSearchProject>(s=>s
+ .From(0)
+ .Size(10)
+ .MatchAll()
+ .FacetQuery("wow_facet", q=>q
+ .Term(f=>f.Name, "elasticsearch.pm")
+ );
+);
+
+
+See original docs for more information
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
range facet allow to specify a set of ranges and get both the number of docs (count) that fall within each range, and aggregated data either based on the field, or using another field. Here is a simple example:
+ +this.ConnectedClient.Search<ElasticSearchProject>(s=>s
+ .From(0)
+ .Size(10)
+ .MatchAll()
+ .FacetRange<int>(t => t
+ .OnField(f => f.LOC)
+ .Ranges(
+ r=>r.To(50),
+ r=>r.From(50).To(100),
+ r=>r.From(100).To(150),
+ r=>r.From(150).To(200),
+ r=>r.From(200).To(250),
+ r=>r.From(250)
+ )
+ );
+);
+
+
+Ranges can also be passed as double
:
//SNIP
+.FacetRange<double>(t => t
+.OnField(f => f.LOC)
+ .Ranges(
+ r => r.To(50.0),
+ r => r.From(50.0).To(100.0),
+ r => r.From(100.0)
+ )
+)
+//SNIP
+
+
+or DateTime
:
//SNIP
+.FacetRange<DateTime>(t => t
+ .OnField(f => f.StartedOn)
+ .Ranges(
+ r => r.To(new DateTime(1990,1,1).Date)
+ )
+);
+//SNIP
+
+
+You can also pass scripts to create complex range facets:
+ +//SNIP
+.FacetRange<DateTime>("needs_a_name", t => t
+ .KeyScript("doc['date'].date.minuteOfHour")
+ .ValueScript("doc['num1'].value")
+ .Ranges(
+ r => r.To(new DateTime(1990, 1, 1).Date)
+ )
+)
+//SNIP
+
+
+or alternative key/value fields
+ +//SNIP
+.FacetRange<DateTime>("needs_a_name", t => t
+ .KeyField("field_name")
+ .ValueField("another_field_name")
+ .Ranges(
+ r => r.To(new DateTime(1990, 1, 1).Date)
+ )
+);
+//SNIP
+
+
+See original docs for more information
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
Statistical facet allows to compute statistical data on a numeric fields. The statistical data include count, total, sum of squares, mean (average), minimum, maximum, variance, and standard deviation. Here is an example:
+ +this.ConnectedClient.Search<ElasticSearchProject>(s=>s
+ .From(0)
+ .Size(10)
+ .MatchAll()
+ .FacetStatistical(sf=>sf
+ .OnField(f=>f.LOC)
+ )
+);
+
+
+See original docs for more information
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
The terms_stats facet combines both the terms and statistical allowing to compute stats computed on a field, per term value driven by another field. For example:
+ +this.ConnectedClient.Search<ElasticSearchProject>(s=>s
+ .From(0)
+ .Size(10)
+ .MatchAll()
+ .FacetTerm(t => t.OnField(f => f.Country).Size(20))
+);
+
+
+See original docs for more information
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
Allow to specify field facets that return the N most frequent terms. For example:
+ +this.ConnectedClient.Search<ElasticSearchProject>(s=>s
+ .From(0)
+ .Size(10)
+ .MatchAll()
+ .FacetTerm(t => t.OnField(f => f.Country).Size(20))
+);
+
+
+See original docs for more information
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
This is sadly still a marker file.
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
This is sadly still a marker file.
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
This is sadly still a marker file.
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
This is sadly still a marker file.
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
This is sadly still a marker file.
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
This is sadly still a marker file.
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
This is sadly still a marker file.
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
This is sadly still a marker file.
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
This is sadly still a marker file.
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
This is sadly still a marker file.
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
This is sadly still a marker file.
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
This is sadly still a marker file.
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
This is sadly still a marker file.
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
This is sadly still a marker file.
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
This is sadly still a marker file.
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
This is sadly still a marker file.
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
This is sadly still a marker file.
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
This is sadly still a marker file.
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
This is sadly still a marker file.
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
This is sadly still a marker file.
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
This is sadly still a marker file.
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
This is sadly still a marker file.
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
This is sadly still a marker file.
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
NEST aims to be a .net client with a very concise API. Its main goal is to provide a solid strongly typed Elasticsearch client. It also has string/dynamic overloads for more dynamic usecases.
+ +Indexing is as simple as:
+ +var post = new Post() { Id = 12, ... }
+client.Index(post);
+
+
+Indexing asynchronously is as easy as:
+ +client.IndexAsync(post, (c) => /* called later */);
+
+
+Searching is fluid:
+ +var results = this.ConnectedClient.Search<ElasticSearchProject>(s => s
+ .From(0)
+ .Size(10)
+ .Fields(f => f.Id, f => f.Name)
+ .SortAscending(f => f.LOC)
+ .SortDescending(f => f.Name)
+ .Query(q=>q.Term(f=>f.Name, "NEST", Boost: 2.0))
+);
+
+
+For more examples please refer to the Wiki
+ + + +To get a good overview of the status of NEST please keep an eye out on the public Roadmap
+ +Copyright (c) 2010 Martijn Laarman and everyone wonderful enough to contribute to NEST
+ +A special shoutout to @stephenpope for allowing his port +of the java factory based dsl Rubber to be merged into NEST. +NEST now has two types of query dsl's (lambda and factory based)!
+ +Some of the other wonderful features in NEST were pushed by these wonderful folks:
+ + + +NEST is licensed under MIT. Refer to license.txt for more information.
+ + + +NEST aims to be a .net client with a very concise API. Its main goal is to provide a solid strongly typed Elasticsearch client. It also has string/dynamic overloads for more dynamic usecases.
+ +Indexing is as simple as:
+ +var post = new Post() { Id = 12, ... }
+client.Index(post);
+
+
+Indexing asynchronously is as easy as:
+ +//IndexAsync returns a Task<ConnectionStatus>
+var task = client.IndexAsync(post);
+
+
+Searching is fluid:
+ +var results = this.ConnectedClient.Search<ElasticSearchProject>(s => s
+ .From(0)
+ .Size(10)
+ .Fields(f => f.Id, f => f.Name)
+ .SortAscending(f => f.LOC)
+ .SortDescending(f => f.Name)
+ .Query(q=>q.Term(f=>f.Name, "NEST", Boost: 2.0))
+);
+
+
+Nest can be installed through NuGet:
+ +PM> Install-Package NEST
+
+
+Or searching for "elasticsearch" will get you to nest as well.
+ +Copyright (c) 2010 Martijn Laarman and everyone wonderful enough to contribute to NEST
+ +NEST is licensed under MIT. Refer to license.txt for more information.
+ +A special shoutout to @stephenpope for allowing his port +of the java factory based dsl Rubber to be merged into NEST. +NEST now has two types of query dsl's (lambda and factory based)!
+ +Some of the other wonderful features in NEST were pushed by these wonderful folks:
+ + + + + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
var response = this.ConnectedClient.Alias("nest_test_data", "nest_test_data2");
+
+
+var response = this.ConnectedClient.Rename("nest_test_data", "nest_test_data2", "nest_test_data3");
+
+
+var response = this.ConnectedClient.RemoveAlias("nest_test_data", "nest_test_data3");
+
+
+
+ + Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
Performs the analysis process on a text and return the tokens breakdown of the text.
+ +var text = "this is a string with some spaces and stuff";
+var r = this.ConnectedClient.Analyze(text);
+
+
+var text = "this is a string with some spaces and stuff";
+var r = this.ConnectedClient.Analyze<ElasticSearchProject>(p => p.Content, text);
+
+
+var analyzer = new AnalyzeParams { Analyzer = "whitespace", Index = Test.Default.DefaultIndex + "_clone" };
+var r = this.ConnectedClient.Analyze(analyzer, text);
+
+
+
+ + Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
The clear cache API allows to clear either all caches or specific cached associated with one ore more indices.
+ +var r = this.ConnectedClient.ClearCache();
+
+
+var r = this.ConnectedClient.ClearCache<ElasticSearchProject>(ClearCacheOptions.Filter | ClearCacheOptions.Bloom);
+
+
+
+ + Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
The create index API allows to instantiate an index. ElasticSearch provides support for multiple indices, including executing operations across several indices. Each index created can have specific settings associated with it.
+ +When adding settings strip the index.
prefix when passing settings found for example here:http://www.elasticsearch.org/guide/reference/index-modules/
var client = this.ConnectedClient;
+var settings = new IndexSettings();
+settings.NumberOfReplicas = 1;
+settings.NumberOfShards = 5;
+settings.Add("merge.policy.merge_factor","10");
+settings.Add("search.slowlog.threshold.fetch.warn", "1s");
+client.CreateIndex("myindexname", settings);
+
+
+var typeMapping = new TypeMapping("mytype");
+var type = new TypeMappingProperty
+{
+ Type = "string",
+ Index = "not_analyzed",
+ Boost = 2.0
+ // Many more options available
+};
+typeMapping.Properties = new Dictionary<string, TypeMappingProperty>();
+typeMapping.Properties.Add("name", type);
+
+var settings = new IndexSettings();
+settings.Mappings.Add(typeMapping);
+settings.NumberOfReplicas = 1;
+settings.NumberOfShards = 5;
+settings.Analysis.Analyzer.Add("snowball", new SnowballAnalyzerSettings { Language = "English" });
+
+var indexName = Guid.NewGuid().ToString();
+var response = client.CreateIndex(indexName, settings);
+
+
+Creates a multimap field "name"
+ +var client = this.ConnectedClient;
+var typeMapping = new TypeMapping(Guid.NewGuid().ToString("n"));
+var property = new TypeMappingProperty
+{
+ Type = "multi_field"
+};
+
+var primaryField = new TypeMappingProperty
+{
+ Type = "string",
+ Index = "not_analyzed"
+};
+var analyzedField = new TypeMappingProperty
+{
+ Type = "string",
+ Index = "analyzed"
+};
+
+property.Fields = new Dictionary<string, TypeMappingProperty>();
+property.Fields.Add("name", primaryField);
+property.Fields.Add("name_analyzed", analyzedField);
+
+typeMapping.Properties.Add("name", property);
+var settings = new IndexSettings();
+settings.Mappings.Add(typeMapping);
+settings.NumberOfReplicas = 1;
+settings.NumberOfShards = 5;
+settings.Analysis.Analyzer.Add("snowball", new SnowballAnalyzerSettings { Language = "English" });
+
+var indexName = Guid.NewGuid().ToString();
+var response = client.CreateIndex(indexName, settings);
+
+
+
+ + Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
The delete index API allows to delete an existing index.
+ +The delete index API can also be applied to more than one index, or on _all
indices (be careful!). All indices will also be deleted when no specific index is provided. In order to disable allowing to delete all indices, set action.disable_delete_all_indices
setting in the config to true
.
Using the default index
+ +this.ConnectedClient.DeleteIndex<ElasticSearchProject>()
+
+
+or more explictly
+ +this.ConnectedClient.DeleteIndex("index")
+
+
+
+ + Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
Allow to delete a mapping (type) along with its data. The REST endpoint is /{index}/{type}
with DELETE
method.
Note, most times, it make more sense to reindex the data into a fresh index compared to delete large chunks of it.
+ +Using the default index and the inferred type name
+ +this.ConnectedClient.DeleteMapping<ElasticSearchProject>()
+
+
+or more explictly:
+ +this.ConnectedClient.DeleteMapping<ElasticSearchProject>("alternateindex","alternatetypename")
+
+
+
+ + Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
var r = this.ConnectedClient.Flush();
+
+
+var r = this.ConnectedClient.Flush("index");
+
+
+var r = this.ConnectedClient.Flush(new[] { "index", "index2" });
+
+
+var r = this.ConnectedClient.Flush<ElasticSearchProject>(true);
+
+
+
+ + Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
The get mapping API allows to retrieve mapping definition of index or index/type.
+ +var mapping = this.ConnectedClient.GetMapping<ElasticSearchProject>();
+
+
+
+ + Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
The get settings API allows to retrieve settings of index/indices
+ +var r = this.ConnectedClient.GetIndexSettings(index);
+Assert.True(r.Success);
+Assert.NotNull(r.Settings);
+Assert.AreEqual(r.Settings.NumberOfReplicas, 4);
+Assert.AreEqual(r.Settings.NumberOfShards, 8);
+Assert.Greater(r.Settings.Count(), 0);
+Assert.True(r.Settings.ContainsKey("merge.policy.merge_factor"));
+
+
+
+ + Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
Used to check if the index (indices) exists or not.
+ +var r = this.ConnectedClient.IndexExists("yadadadadadaadada");
+Assert.False(r.Exists);
+//404 is a valid response in this case
+Assert.True(r.IsValid);
+
+
+var r = this.ConnectedClient.IndexExists("nest_test_data");
+Assert.True(r.Exists);
+
+
+
+ + Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
The open and close index APIs allow to close an index, and later on opening it. A closed index has almost no overhead on the cluster (except for maintaining its metadata), and is blocked for read/write operations. A closed index can be opened which will then go through the normal recovery process.
+ +var r = this.ConnectedClient.CloseIndex(Test.Default.DefaultIndex);
+r = this.ConnectedClient.OpenIndex(Test.Default.DefaultIndex);
+
+
+var r = this.ConnectedClient.CloseIndex<ElasticSearchProject>();
+r = this.ConnectedClient.OpenIndex<ElasticSearchProject>();
+
+
+
+ + Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
The optimize API allows to optimize one or more indices through an API. The optimize process basically optimizes the index for faster search operations (and relates to the number of segments a lucene index within each shard). The optimize operation allows to optimize the number of segments to optimize to.
+ +var r = this.ConnectedClient.Optimize();
+
+
+var r = this.ConnectedClient.Optimize(new[] { "index", "index2" }, new OptimizeParams {MaximumSegments=2});
+
+
+More overloads exists and all OptimizeParams are mapped. See the original docs for parameters
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
The put mapping API allows to register specific mapping definition for a specific type.
+ +You can decorate your classes with ElasticProperty
and ElasticType
attributes to describe how they should be mapped in ES.
[ElasticType(
+ Name = "elasticsearchprojects2",
+ DateDetection = true,
+ NumericDetection = true,
+ SearchAnalyzer = "standard",
+ IndexAnalyzer = "standard",
+ DynamicDateFormats = new[] { "dateOptionalTime", "yyyy/MM/dd HH:mm:ss Z||yyyy/MM/dd Z" }
+)]
+public class ElasticSearchProject
+{
+ public int Id { get; set; }
+ public string Name { get; set; }
+ [ElasticProperty(OmitNorms = true, Index = FieldIndexOption.not_analyzed)]
+ public string Country { get; set; }
+ public string Content { get; set; }
+ [ElasticProperty(Name="loc")]
+ public int LOC { get; set; }
+ public List<Person> Followers { get; set; }
+
+ [ElasticProperty(Type=FieldType.geo_point)]
+ public GeoLocation Origin { get; set; }
+ public DateTime StartedOn { get; set; }
+
+
+ //excuse the lame properties i needed some numerics !
+ public long LongValue { get; set; }
+ public float FloatValue { get; set; }
+ public double DoubleValue { get; set; }
+
+ [ElasticProperty(NumericType=NumericType.Long)]
+ public int StupidIntIWantAsLong { get; set; }
+}
+
+
+You can persist this mapping by simpling calling
+ +var response = this.ConnectedClient.Map<ElasticSearchProject>();
+
+
+NOTE: Whenever the client needs to infer the typename for ElasticSearchProject
it will resolve nicely to "elasticsearchprojects2"
now too. This gives you great control over naming without having to specify the typename on each call.
ALSO NOTE: Map<T>()
will also explicitly map string properties as strings with elasticsearch even if they do not have an attribute on them. It does this for all the value types (string, int, float, double, DateTime).
You can also create mappings on the fly:
+ +var typeMapping = new TypeMapping(Guid.NewGuid().ToString("n"));
+var property = new TypeMappingProperty
+{
+ Type = "multi_field"
+};
+
+var primaryField = new TypeMappingProperty
+{
+ Type = "string",
+ Index = "not_analyzed"
+};
+
+var analyzedField = new TypeMappingProperty
+{
+ Type = "string",
+ Index = "analyzed"
+};
+
+property.Fields = new Dictionary<string, TypeMappingProperty>();
+property.Fields.Add("name", primaryField);
+property.Fields.Add("name_analyzed", analyzedField);
+
+typeMapping.Properties.Add("name", property);
+this.ConnectedClient.Map(typeMapping);
+
+
+
+ + Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
The refresh API allows to explicitly refresh one or more index, making all operations performed since the last refresh available for search. The (near) real-time capabilities depends on the index engine used. For example, the robin one requires refresh to be called, but by default a refresh is scheduled periodically.
+ +var r = this.ConnectedClient.Refresh();
+
+
+var r = this.ConnectedClient.Refresh("index");
+r = this.ConnectedClient.Refresh(new [] {"index4", "index2" });
+
+
+var r = this.ConnectedClient.Refresh<ElasticSearchProject>();
+
+
+
+ + Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
Provide low level segments information that a Lucene index (shard level) is built with. Allows to be used to provide more information on the state of a shard and an index, possibly optimization information, data “wasted” on deletes, and so on.
+ +var r = this.ConnectedClient.Segments();
+r.Indices[this.Settings.DefaultIndex].Shards["0"].Segments["_l"].SizeInBytes;
+
+
+
+ + Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
The gateway snapshot API allows to explicitly perform a snapshot through the gateway of one or more indices (backup them). By default, each index gateway periodically snapshot changes, though it can be disabled and be controlled completely through this API.
+ +Note, this API only applies when using shared storage gateway implementation, and does not apply when using the (default) local gateway.
+ +var r = this.ConnectedClient.Snapshot();
+
+
+var r = this.ConnectedClient.Snapshot("index");
+
+
+var r = this.ConnectedClient.Snapshot<ElasticSearchProject>();
+
+
+
+ + Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
Indices level stats provide statistics on different operations happening on an index. The API provides statistics on the index level scope (though most stats can also be retrieved using node level scope).
+ +var r = this.ConnectedClient.Stats();
+var deletedOnPrimaries = r.Stats.Primaries.Documents.Deleted;
+var deletedOnIndexPrimaries = r.Stats.Indices["nest_test_data"].Primaries.Documents.Count;
+
+
+var r = this.ConnectedClient.Stats("nest_test_data");
+var deletedOnIndexPrimaries = r.Stats.Primaries.Documents.Deleted;
+
+
+var r = this.ConnectedClient.Stats(new StatsParams()
+{
+ InfoOn = StatsInfo.All,
+ Refresh = true,
+ Types = new List<string>{ "elasticsearchprojects" }
+
+});
+var x = r.Stats.Primaries.Indexing.Types["elasticsearchprojects"].Current;
+
+
+
+ + Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
The status api hasn't been mapped yet.
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
The index templates api is not currently mapped in NEST.
+ + ++ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
This call allows you to update the index settings.
+NEST whitelists which settings can be updated based on the allowed values mentioned here in the elasticsearch documentation this allows you to reuse an IndexSettings
object.
this example first creates an index and then uses the same IndexSettings to update the index.
+ +var index = Guid.NewGuid().ToString();
+var client = this.ConnectedClient;
+var settings = new IndexSettings();
+settings.NumberOfReplicas = 1;
+settings.NumberOfShards = 5;
+settings.Add("refresh_interval", "1s");
+settings.Add("search.slowlog.threshold.fetch.warn", "1s");
+client.CreateIndex(index, settings);
+
+settings["refresh_interval"] = "-1";
+settings["search.slowlog.threshold.fetch.warn"] = "5s";
+
+var r = this.ConnectedClient.UpdateSettings(index, settings);
+
+Assert.True(r.Success);
+Assert.True(r.OK);
+var getResponse = this.ConnectedClient.GetIndexSettings(index);
+Assert.AreEqual(getResponse.Settings["refresh_interval"], "-1");
+Assert.AreEqual(getResponse.Settings["search.slowlog.threshold.fetch.warn"], "1s");
+
+
+
+ + Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
=5&&'lang-'===t.substring(0,5),n&&!(p&&typeof +p[1]==='string')&&(n=false,t='src'),n||(u[w]=t)}x=s,s+=w.length,n?(j=p[1],l=w.indexOf(j),k=l+j.length,p[2]&&(k=w.length-p[2].length,l=k-j.length),o=t.substring(5),R(g+x,w.substring(0,l),e,i),R(g+x+l,j,W(o,j),i),R(g+x+k,w.substring(k),e,i)):i.push(g+x,t)}a.decorations=i},e}function +T(a){var c=[],d=[],e,f;return a.tripleQuotedStrings?c.push(['str',/^(?:\'\'\'(?:[^\'\\]|\\[\s\S]|\'{1,2}(?=[^\']))*(?:\'\'\'|$)|\"\"\"(?:[^\"\\]|\\[\s\S]|\"{1,2}(?=[^\"]))*(?:\"\"\"|$)|\'(?:[^\\\']|\\[\s\S])*(?:\'|$)|\"(?:[^\\\"]|\\[\s\S])*(?:\"|$))/,b,'\'\"']):a.multiLineStrings?c.push(['str',/^(?:\'(?:[^\\\']|\\[\s\S])*(?:\'|$)|\"(?:[^\\\"]|\\[\s\S])*(?:\"|$)|\`(?:[^\\\`]|\\[\s\S])*(?:\`|$))/,b,'\'\"`']):c.push(['str',/^(?:\'(?:[^\\\'\r\n]|\\.)*(?:\'|$)|\"(?:[^\\\"\r\n]|\\.)*(?:\"|$))/,b,'\"\'']),a.verbatimStrings&&d.push(['str',/^@\"(?:[^\"]|\"\")*(?:\"|$)/,b]),a.hashComments&&(a.cStyleComments?(c.push(['com',/^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\r\n]*)/,b,'#']),d.push(['str',/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,b])):c.push(['com',/^#[^\r\n]*/,b,'#'])),a.cStyleComments&&(d.push(['com',/^\/\/[^\r\n]*/,b]),d.push(['com',/^\/\*[\s\S]*?(?:\*\/|$)/,b])),a.regexLiterals&&(e='/(?=[^/*])(?:[^/\\x5B\\x5C]|\\x5C[\\s\\S]|\\x5B(?:[^\\x5C\\x5D]|\\x5C[\\s\\S])*(?:\\x5D|$))+/',d.push(['lang-regex',new +RegExp('^'+m+'('+e+')')])),f=a.keywords.replace(/^\s+|\s+$/g,''),f.length&&d.push(['kwd',new +RegExp('^(?:'+f.replace(/\s+/g,'|')+')\\b'),b]),c.push(['pln',/^\s+/,b,' \r\n \xa0']),d.push(['lit',/^@[a-z_$][a-z_$@0-9]*/i,b],['typ',/^@?[A-Z]+[a-z][A-Za-z_$@0-9]*/,b],['pln',/^[a-z_$][a-z_$@0-9]*/i,b],['lit',new +RegExp('^(?:0x[a-f0-9]+|(?:\\d(?:_\\d+)*\\d*(?:\\.\\d*)?|\\.\\d\\+)(?:e[+\\-]?\\d+)?)[a-z]*','i'),b,'0123456789'],['pun',/^.[^\s\w\.$@\'\"\`\/\#]*/,b]),S(c,d)}s=T({keywords:l,hashComments:a,cStyleComments:a,multiLineStrings:a,regexLiterals:a});function +U(c){var d=c.source,e=c.extractedTags,f=c.decorations,g=[],h=0,i=b,j=b,k=0,l=0,m=O(window.PR_TAB_WIDTH),n=/([\r\n ]) /g,o=/(^| ) /gm,p=/\r\n?|\n/g,q=/[ \r\n]$/,r=a,s;function +t(a){var c,e;a>h&&(i&&i!==j&&(g.push(''),i=b),!i&&j&&(i=j,g.push('')),c=H(m(d.substring(h,a))).replace(r?o:n,'$1 '),r=q.test(c),e=window._pr_isIE6()?'
':'
',g.push(c.replace(p,e)),h=a)}while(a){k'),i=b),g.push(e[k+1]),k+=2;else +if(l '),c.prettyPrintedHtml=g.join('')}t={};function +V(a,b){var c,d;for(d=b.length;--d>=0;)c=b[d],t.hasOwnProperty(c)?'console'in window&&console.warn('cannot override language handler %s',c):(t[c]=a)}function +W(a,b){return a&&t.hasOwnProperty(a)||(a=/^\s*]*(?:>|$)/],['com',/^<\!--[\s\S]*?(?:-\->|$)/],['lang-',/^<\?([\s\S]+?)(?:\?>|$)/],['lang-',/^<%([\s\S]+?)(?:%>|$)/],['pun',/^(?:<[%?]|[%?]>)/],['lang-',/^ ]*>([\s\S]+?)<\/xmp\b[^>]*>/i],['lang-js',/^ + + + + + + + + + + + + ++ +++Bool Query
+ +A query that matches documents matching boolean combinations of other queries. The bool query maps to Lucene BooleanQuery. It is built using one or more boolean clauses, each clause with a typed occurrence.
+ ++ +
.Query(qd=>qd + .Bool(b=>b + .Must(q => q.MatchAll()) + .MustNot(q => q.Term(p => p.Name, "elasticsearch.pm")) + .Should(q => q.Term(p => p.Name, "elasticflume")) + ) +) +
note each clause can take multiple queries e.g:
+ ++ + + Be sure to read the original documentation + on this subject. + +
.Should( + q => q.Term(p => p.Name, "elasticflume"), + q => q.Term(p => p.Name, "Nest") + +) +
+ Spotted a mistake? Something to add? + + Fork and edit this file on github + + without leaving the browser + +
+ + + + +