I have recently upgraded Elasticsearch.Net
and NEST
in my application from Version 5.5.0 to 7.5.1 and I am getting a bunch of build errors. I've managed to resolve some of them but the following ones remain unclear to me:
1) ElasticLowLevelClient.Msearch
MultiSearchRequest multiSearchRequest = new MultiSearchRequest { Operations = operations };
MultiSearchResponseData response = Converter.ToMultiSearchResponseData(client.Msearch<byte[]>("articles", multiSearchRequest));
Where operations
is of type Dictionary<string, Nest.ISearchRequest>
, I am getting the following error:
Severity Code Description Project File Line Suppression State Error CS1061 'ElasticLowLevelClient' does not contain a definition for 'Msearch' and no accessible extension method 'Msearch' accepting a first argument of type 'ElasticLowLevelClient' could be found (are you missing a using directive or an assembly reference?)
2) Elasticsearch.Net.PostData
SearchRequest request = new SearchRequest
{
Size = 1,
Query = new QueryStringQuery { DefaultField = new Field("urlName"), Query = "(" + articleUrl + ")" },
};
ElasticsearchResponse<string> response = client.Search<string>("detailarticle", new PostData<object>(request));
I am getting the following error:
Severity Code Description Project File Line Suppression State Error CS1729 'PostData' does not contain a constructor that takes 1 arguments
3) BulkUpdateOperation and PostDate:
public void UpdateArticlesIndex(IEnumerable<ArticleUpdateModel> articles)
{
if (articles == null || articles.Count() == 0)
return;
List<IBulkOperation> operations = new List<IBulkOperation>();
foreach (var a in articles)
{
operations.Add(new BulkUpdateOperation<object, object>(a.DocumentId)
{
Index = "articles",
Type = "_doc",
Doc = a.Value,
});
}
BulkRequest request = new BulkRequest
{
Operations = operations,
};
client.Bulk<string>(new PostData<object>(request));
}
I am getting the following two erros:
Severity Code Description Project File Line Suppression State Error CS0117 'BulkUpdateOperation<object, object>' does not contain a definition for 'Type'
and
Severity Code Description Project File Line Suppression State Error CS1729 'PostData' does not contain a constructor that takes 1 arguments
I have tried messing with constructors and altering declarations but it did not yield any desired results. I have also looked into Elasticsearch documentation but did not find anything relevant
Any help about resolving those build errors would be highly appreciated
ElasticLowLevelClient.Msearch
MultiSearchRequest multiSearchRequest = new MultiSearchRequest { Operations = operations }; MultiSearchResponseData response = Converter.ToMultiSearchResponseData(client.Msearch<byte[]>("articles", multiSearchRequest)); Where operations is of type Dictionary<string, Nest.ISearchRequest>, I am getting the following error:
Severity Code Description Project File Line Suppression State Error CS1061 'ElasticLowLevelClient' does not contain a definition for 'Msearch' and no accessible extension method 'Msearch' accepting a first argument of type 'ElasticLowLevelClient' could be found (are you missing a using directive or an assembly reference?)
Use MultiSearch
instead of Msearch
, wrap MultiSearchRequest
in PostData.Serialiable
and change the response type from byte[]
to BytesResponse
. Note that the low level client must be accessed from an instance of a high level client so that MultiSearchRequest
is serialized correctly (more specifically, ConnectionSettings
should be used, which is configured with a resolver that will use the correct formatter to JSON serialize MultiSearchRequest
correctly)
var client = new ElasticClient();
MultiSearchRequest multiSearchRequest = new MultiSearchRequest { Operations = operations };
var response = client.LowLevel.MultiSearch<BytesResponse>("articles", PostData.Serializable(multiSearchRequest));
byte[] bytes = response.Body;
Elasticsearch.Net.PostData
SearchRequest request = new SearchRequest { Size = 1, Query = new QueryStringQuery { DefaultField = new Field("urlName"), Query = "(" + articleUrl + ")" }, }; ElasticsearchResponse response = client.Search("detailarticle", new PostData(request)); I am getting the following error:
Severity Code Description Project File Line Suppression State Error CS1729 'PostData' does not contain a constructor that takes 1 arguments
Use PostData.Serializable<T>(T data)
and return a StringResponse
var client = new ElasticClient();
var articleUrl = "example.com";
SearchRequest request = new SearchRequest
{
Size = 1,
Query = new QueryStringQuery { DefaultField = new Field("urlName"), Query = "(" + articleUrl + ")" },
};
var response = client.LowLevel.Search<StringResponse>("detailarticle", PostData.Serializable(request));
var str = response.Body;
I am getting the following two erros:
Severity Code Description Project File Line Suppression State Error CS0117 'BulkUpdateOperation<object, object>' does not contain a definition for 'Type'
and
Severity Code Description Project File Line Suppression State Error CS1729 'PostData' does not contain a constructor that takes 1 arguments
Remove Type
as types are going away in Elasticsearch and have been removed in NEST 7.x for bulk requests. The client will use _doc
for APIs. Similar to the answer to 2, you should wrap BulkRequest
in PostData.Serializable<T>(T data)