Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用嵌套索引大型JSON_C#_Json_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_.net Core_Nest - Fatal编程技术网 elasticsearch,.net-core,nest,C#,Json,elasticsearch,.net Core,Nest" /> elasticsearch,.net-core,nest,C#,Json,elasticsearch,.net Core,Nest" />

C# 使用嵌套索引大型JSON

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

我正在尝试向ElasticSearch索引添加一个大的JSON(大约22k行)文件,但我无法这样做,因为无论我尝试了什么,ElasticSearch都会收到错误响应。我正在使用ElasticSearch 7.6.2,我正在使用NEST与ElasticSearch进行通信

我将只添加与问题相关的代码

首先,我创建如下连接设置:

_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);
在第一次尝试中,它起到了作用,它可能会帮助像我这样使用高级客户机的人。(注意:我假设有一种方法可以通过使用高级客户端实现我想做的事情,我只是还没有弄明白)