gpt4 book ai didi

c# - 从Elasticsearch 5.5.0升级到7.5.1后的构建错误

转载 作者:行者123 更新时间:2023-12-02 22:26:54 24 4
gpt4 key购买 nike

我最近将我的应用程序中的Elasticsearch.NetNEST从5.5.0升级到7.5.1,并且遇到了很多构建错误。我设法解决了其中一些问题,但以下几个问题我仍然不清楚:
1)ElasticLowLevelClient.Msearch

    MultiSearchRequest multiSearchRequest = new MultiSearchRequest { Operations = operations };
MultiSearchResponseData response = Converter.ToMultiSearchResponseData(client.Msearch<byte[]>("articles", multiSearchRequest));
operations的类型为 Dictionary<string, Nest.ISearchRequest>的地方,出现以下错误:
严重性代码说明项目文件行抑制状态
错误CS1061'ElasticLowLevelClient'不包含'Msearch'的定义,并且找不到可以接受的扩展方法'Msearch'接受类型为'ElasticLowLevelClient'的第一个参数(您是否缺少using指令或程序集引用?)

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));
我收到以下错误:
严重性代码说明项目文件行抑制状态
错误CS1729'PostData'不包含带有1个参数
的构造函数
3)BulkUpdateOperation和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));
}
我得到以下两个错误:
严重性代码说明项目文件行抑制状态
错误CS0117“BulkUpdateOperation <对象,对象>”不包含“类型”的定义


严重性代码说明项目文件行抑制状态
错误CS1729'PostData'不包含带有1个参数
的构造函数
我尝试过弄乱构造函数并更改声明,但未产生任何期望的结果。我也查看了Elasticsearch文档,但没有找到任何相关内容
解决这些构建错误的任何帮助将不胜感激

最佳答案

  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 ErrorCS1061 'ElasticLowLevelClient' does not contain a definition for'Msearch' and no accessible extension method 'Msearch' accepting afirst argument of type 'ElasticLowLevelClient' could be found (are youmissing a using directive or an assembly reference?)


使用 MultiSearch代替 Msearch,将 MultiSearchRequest包装在 PostData.Serialiable中,并将响应类型从 byte[]更改为 BytesResponse。请注意,必须从高级别客户端的实例访问低级别客户端,以便正确地序列化 MultiSearchRequest(更具体地说,应使用 ConnectionSettings,它已配置有解析器,该解析器将使用正确的格式化程序来对JSONt_code进行JSON正确序列化)
var client = new ElasticClient();
MultiSearchRequest multiSearchRequest = new MultiSearchRequest { Operations = operations };
var response = client.LowLevel.MultiSearch<BytesResponse>("articles", PostData.Serializable(multiSearchRequest));
byte[] bytes = response.Body;
  1. 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 ErrorCS1729 'PostData' does not contain a constructor that takes 1arguments


使用 MultiSearchRequest并返回一个 PostData.Serializable<T>(T data)
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 ErrorCS0117 'BulkUpdateOperation<object, object>' does not contain adefinition for 'Type'

and

Severity Code Description Project File Line Suppression State ErrorCS1729 'PostData' does not contain a constructor that takes 1arguments


删除 StringResponse,因为Elasticsearch中的类型将消失,并且已在NEST 7.x中针对批量请求被删除。客户端将对API使用 Type。与答案2相似,您应该将 _doc包装在 BulkRequest

关于c# - 从Elasticsearch 5.5.0升级到7.5.1后的构建错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62959673/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com