使用Elasticsearch.net或PlainElastic.net批量插入Elasticsearch

触须

我一直在使用Elasticsearch.net(http://nest.azurewebsites.net/)和PlainElastic.Net(https://github.com/Yegoroff/PlainElastic.Net),并且能够插入单个文档进入elasticsearch。我现在试图弄清楚如何执行批量插入。我知道这两个.net库中的每一个都有与此相关的文档,但是我要插入的数据存储在字典中,其中的键是文档的ID,值是文档,我不知道该怎么做。

这是我有的一些代码(使用Elasticsearch.net):

var conn = new Uri("http://localhost:9200");
var config = new ConnectionConfiguration(conn);
var client = new ElasticsearchClient(config);

var myJson = @"{""Col1"" : ""Hello World"", ""col2"" : ""asdfasdf"" }";
var myjson2 = @"{""Col2"" : ""Hello World Again"", ""col2"" : ""zxcvzxcv"" }";

Dictionary<string, string> jsonCollection = new Dictionary<string, string>();

jsonCollection.Add("1", myJson);
jsonCollection.Add("2", myjson2);
曼努埃尔

我使用PlainElastic.Net,这是RAW数据的外观

POST /_bulk
{ "index" :{ "_index": "myIndex", "_type": "myType", "_id": 1  }}
{ "id": 1, "name": "My category \"ONE\" "}
{ "index" :{ "_index": "myIndex", "_type": "myType", "_id": 2  }}
{ "id": 2, "name": "My second category \t "}
{ "index" :{ "_index": "myIndex", "_type": "myType", "_id": 3 }}
{ "id": 3, "name": "My third category \r\n "}

请记住,新行位于每一行的末尾(即使在最后一行之后也可以)

所以vb.net应该看起来像这样:

Dim bulkData As String = "{ ""index"": { ""_index"": ""myIndex"", ""_type"": ""myType"", ""_id"": 1  }}" & vbNewLine & _
                         "{ ""id"": 1, ""name"": ""My category""}" & vbNewLine & _
                         "{ ""index"": { ""_index"": ""myIndex"", ""_type"": ""myType"", ""_id"": 2  }}" & vbNewLine & _
                         "{ ""id"": 2, ""name"": ""My second category""} " & vbNewLine & _
                         "{ ""index"": { ""_index"": ""myIndex"", ""_type"": ""myType"", ""_id"": 3  }}" & vbNewLine & _
                         "{ ""id"": 3, ""name"": ""My third category""} " & vbNewLine

Dim ESConn as New ElasticConnection("localhost", 9200)
Dim response As String = ESConn.Post("/_bulk", bulkData)

我没有测试过的C#版本,但您会明白的

string bulkData = @"{ ""index"": { ""_index"": ""myIndex"", ""_type"": ""myType"", ""_id"": 1}}
{ ""id"": 1, ""name"": ""My category""}
{ ""index"": { ""_index"": ""myIndex"", ""_type"": ""myType"", ""_id"": 2}}
{ ""id"": 2, ""name"": ""My second category""}
{ ""index"": { ""_index"": ""myIndex"", ""_type"": ""myType"", ""_id"": 3}}
{ ""id"": 3, ""name"": ""My third category""} \n";

ElasticConnection ESConn = New ElasticConnection("localhost", 9200);
string response = ESConn.Post("/_bulk", bulkData);

您可以手动或使用Newtonsoft.Json创建JSON

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

使用NEST批量插入ElasticSearch

来自分类Dev

如何使用NEST elasticsearch批量插入Json?

来自分类Dev

如何使用NEST elasticsearch批量插入Json?

来自分类Dev

ElasticSearch批量插入/更新操作

来自分类Dev

在Elasticsearch中批量插入对象

来自分类Dev

使用Linq批量插入Sql(vb.net)

来自分类Dev

使用Elasticsearch.net创建内存索引

来自分类Dev

elasticsearch.js批量插入错误

来自分类Dev

问题批量插入elasticsearch curl powershell

来自分类Dev

AWS Elasticsearch 批量插入延迟大幅增加

来自分类Dev

在.NET上测试Elasticsearch

来自分类Dev

Elasticsearch和.NET

来自分类Dev

Elasticsearch和.NET

来自分类Dev

使用Dapper .Net使用范围标识批量插入多个关系表中

来自分类Dev

.NET C#如何使用linq2db批量插入?

来自分类Dev

如何在asp.net中使用SQL Server批量插入?

来自分类Dev

对Nest / ElasticSearch.Net使用普通的双纬度/经度属性

来自分类Dev

.NET / EF Core中的批量插入优化

来自分类Dev

在ElasticSearch批量上传中,如何用单引号插入数据?

来自分类Dev

使用NEST在ElasticSearch上进行批量更新

来自分类Dev

如何使用php从Elasticsearch批量删除文档

来自分类Dev

使用 bulkProcessor 时捕获 Elasticsearch 批量错误

来自分类Dev

使用 Python 进行 Elasticsearch 批量响应

来自分类Dev

Elasticsearch批量API错误

来自分类Dev

.Net Core中没有DataTable的SqlClient批量插入

来自分类Dev

在.Net Core中在后台插入批量数据

来自分类Dev

在Elasticsearch.net,Nest上将Stop过滤器与stopword_path一起使用

来自分类Dev

使用NEST和.NET从Elasticsearch返回多个派生类实例

来自分类Dev

使用Log4Net时将整数值存储到ElasticSearch中

Related 相关文章

热门标签

归档