Skip to content

Upgrading NEST 1 to 2

Breaking1.9.2 โ†’ 2.5.8Breaking20Platform1Deprecated12New60Changed43Fixed127Other12

BreakingUpgrade verdict

18 breaking changes and a platform requirement change.

  • When a document is missing, get and delete calls no longer report an invalid response; instead they succeed and you must check whether the document was found.
  • Removes `RethrowKeepingStackTrace` in favour of simply `throw`ing the exception.
  • The low-level client interface has a new name, so code referring to the old name must be updated.
  • Update now supports fields and is no longer generic.
Top 5 of 31 that need code or config changes

Requires Target frameworks .NETFramework4.5, .NETFramework4.6, .NETStandard1.3 from 2.4.0 (none stated before).

Adds netstandard.library 1.6.0, system.collections.specialized 4.3.0, system.linq.queryable 4.0.1, system.reflection.typeextensions 4.3.0.

Moves elasticsearch.net [1.9.2, 2.0) โ†’ [2.5.8, 3.0.0), newtonsoft.json [9.0, 10.0) โ†’ [11.0.1, 12.0.0). Your build may pick other versions.

Breaking18
404s on Get<T>() and Delete<T>() (and async variants) now return .IsValid as true and deserialize the response, setting .Found.
Get<T>()Delete<T>().IsValid.Found
Removes RethrowKeepingStackTrace in favour of simply throwing the exception.
RethrowKeepingStackTrace
Renames IElasticsearchClient to IElasticLowLevelClient to better specify intent.
IElasticsearchClientIElasticLowLevelClient
Update now supports fields and is no longer generic.
Update
Renames ConnectionStatusHandler to OnRequestCompleted and restores its functionality.
ConnectionStatusHandlerOnRequestCompleted
Removes filter constructs from the code base to reflect the removal of filters in Elasticsearch 2.0.
Splits ElasticPropertyAttribute into individual per-type attributes and renames ElasticTypeAttribute to ElasticsearchTypeAttribute.
ElasticPropertyAttributeElasticTypeAttributeElasticsearchTypeAttributeStringDateNumberNestedElasticType
Moves Analyze API parameters from the query string to the request body.
Analyze
Rewrites NEST internals, replacing TPL-based code with async/await and reworking exception and error handling.
Replaces many NEST 1.x exception types with deterministic ElasticsearchClientException, UnexpectedElasticsearchClientException and CLR runtime exceptions.
MaxRetryExceptionElasticsearchAuthExceptionElasticsearchServerExceptionDslExceptionIConnectionPoolElasticsearchClientExceptionUnexpectedElasticsearchClientException
Merges query and filter constructs into queries, renaming filters such as AndFilter to AndQuery.
AndFilterAndQuery
Requires descending into isolated descriptors, for example Search().Sort(ss=>ss...) instead of SortAscending and SortScript on Search().
Search()SortAscending()SortScript()Sort()Field()Script()Ascending()GeoDistance()
Replaces ElasticPropertyAttribute with type-specific attributes such as ElasticsearchType, String, Date, Number and Nested.
ElasticsearchTypeElasticsearchType.NameElasticsearchType.IdPropertyStringDateNumberNestedElasticPropertyAttribute
Changes many string or primitive parameters to strongly typed objects such as Id, Field, Fields, Index, Indices, Type, Types and DocumentPath<T>.
IdFieldFieldsIndexIndicesTypeTypesDocumentPath<T>
High level methods now take Time instead of TimeSpan.
TimeTimeSpan
Replaces ThrowOnElasticsearchServerExceptions() with ThrowExceptions() to control whether the client throws exceptions.
ThrowOnElasticsearchServerExceptions()ThrowExceptions()
Reduces the exception types the client throws to ElasticsearchClientException, UnexpectedElasticsearchClientException, and development time CLR exceptions.
ElasticsearchClientExceptionUnexpectedElasticsearchClientException
Introduces many breaking changes in NEST 2.0 and revalidates request and response domain objects against Elasticsearch 2.0.
Platform1
NEST 2.0.0-alpha1 supports only .NET 4.5 and up; PCL/.NET Core support is not yet part of the build and CI.
Deprecated12
Introduces EndOffset on AnalyzeToken and deprecates the misspelt EndPostion.
AnalyzeTokenEndOffsetEndPostion
Marks IsValid obsolete for Get and Delete responses to warn about the behavioural change in #2637.
IsValid
Marks type level analyzers as obsolete; they will be removed in Elasticsearch 6.0.
Introduces TookAsLong for the Took value, caps Took at int.MaxValue, and marks Took Obsolete.
TookTookAsLong
Marks properties removed in 5.0 with ObsoleteAttribute.
ObsoleteAttribute
Marks MissingQuery with ObsoleteAttribute as removed in 5.0.
MissingQueryObsoleteAttribute
Marks IndexName on property mappings with ObsoleteAttribute as removed in 5.0.
IndexNameObsoleteAttribute
Marks .Highlights on SearchResponse<T> as obsolete, to be removed in 5.x.
SearchResponse<T>.HighlightsHitsMetaData.Hits
Deprecates Alias on GetAlias() in favour of Name.
GetAlias()AliasName
Deprecates the misnamed Field() method on SuggestContextDescriptor in favor of Path().
SuggestContextDescriptor.Field()SuggestContextDescriptor.Path()
Deprecates factor on DateHistogramAggregation.
factorDateHistogramAggregation
Mappings: Marks PositionOffsetGap as obsolete in favor of PositionIncrementGap.
PositionOffsetGapPositionIncrementGap