C# 使用嵌套索引大型JSON
我正在尝试向ElasticSearch索引添加一个大的JSON(大约22k行)文件,但我无法这样做,因为无论我尝试了什么,ElasticSearch都会收到错误响应。我正在使用ElasticSearch 7.6.2,我正在使用NEST与ElasticSearch进行通信 我将只添加与问题相关的代码 首先,我创建如下连接设置:C# 使用嵌套索引大型JSON,c#,json,
elasticsearch,.net-core,nest,C#,Json,
elasticsearch,.net Core,Nest,我正在尝试向ElasticSearch索引添加一个大的JSON(大约22k行)文件,但我无法这样做,因为无论我尝试了什么,ElasticSearch都会收到错误响应。我正在使用ElasticSearch 7.6.2,我正在使用NEST与ElasticSearch进行通信 我将只添加与问题相关的代码 首先,我创建如下连接设置: _settings = new ConnectionSettings() .DefaultMappingFor
_settings = new ConnectionSettings()
.DefaultMappingFor<string>(m => m // I've put string here because that is the return type of File.ReadAllText() function
.IndexName("jsonindex")
);
_elasticClient.Indices.Create("jsonindex", c => c
.Settings(s => s
.NumberOfShards(1)));
_elasticClient.LowLevel.Index<StringResponse>("jsonindex", json);
我成功地创建了如下索引:
_settings = new ConnectionSettings()
.DefaultMappingFor<string>(m => m // I've put string here because that is the return type of File.ReadAllText() function
.IndexName("jsonindex")
);
_elasticClient.Indices.Create("jsonindex", c => c
.Settings(s => s
.NumberOfShards(1)));
_elasticClient.LowLevel.Index<StringResponse>("jsonindex", json);
设置好所有内容后,我将执行以下操作:
var json = File.ReadAllText("path\to\file.json"); //read the json file
var indexResponse = _elasticClient.IndexDocument(jsonToSend); //try to index it, but this is where I get the error message
我得到以下错误:
Request failed to execute. Call: Status code 400 from: POST /jsonindex/_doc. ServerError: Type: mapper_parsing_exception Reason: "failed to parse" CausedBy: "Type: not_x_content_exception Reason: "Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes""
我还尝试调用.Index()方法并将索引名称指定为第二个参数,但结果是一样的。看起来我在使用高级客户端时没有朝正确的方向前进,我访问了低级客户端,如下所示:
_settings = new ConnectionSettings()
.DefaultMappingFor<string>(m => m // I've put string here because that is the return type of File.ReadAllText() function
.IndexName("jsonindex")
);
_elasticClient.Indices.Create("jsonindex", c => c
.Settings(s => s
.NumberOfShards(1)));
_elasticClient.LowLevel.Index<StringResponse>("jsonindex", json);
\u elasticClient.LowLevel.Index(“jsonindex”,json);
在第一次尝试中,它起到了作用,它可能会帮助像我这样使用高级客户机的人。(注意:我假设有一种方法可以通过使用高级客户端实现我想做的事情,我只是还没有弄明白)