【问题标题】:Elastic search bulk index with C# API使用 C# API 的弹性搜索批量索引
【发布时间】:2018-04-07 20:35:17
【问题描述】:

我想使用 NEST 或 Elasticsearch.Net API 批量索引 json 记录以进行弹性搜索

我的 json 数据是:

{"index":{"_index":"abc","_type":"abc","_id":1}},{"Name":"ApplicationFrameHost","CPU":1.25,"Company":null,"Product":null,"Path":null},{"index":{"_index":"abc","_type":"abc","_id":2}},{"Name":"Calculator","CPU":0.5,"Company":null,"Product":null,"Path":null},{"index":{"_index":"abc","_type":"abc","_id":3}},{"Name":"chrome","CPU":142.9375,"Company":null,"Product":null,"Path":null},{"index":{"_index":"abc","_type":"abc","_id":4}},{"Name":"chrome","CPU":3336.34375,"Company":null,"Product":null,"Path":null},{"index":{"_index":"abc","_type":"abc","_id":5}},{"Name":"chrome","CPU":7.1875,"Company":null,"Product":null,"Path":null}\n\n

我的代码:

 var connectionSettings = new ConnectionSettings(new 
 Uri("http://localhost:9200/"));
        
        var client2 = new ElasticClient(connectionSettings);
       var jsonPostData = new PostData<object>(myJson);
        var bulkRequestParameters = new BulkRequestParameters
        {

        };
  Func<BulkRequestParameters, BulkRequestParameters> convert = delegate 
  (BulkRequestParameters s)
        {
            s.ErrorTrace(true);
            
            return s.Refresh(Refresh.True); 
        };

        var response = client2.LowLevel.Bulk<VoidResponse>("abc", "abc", 
        jsonPostData, convert);

在响应弹性返回成功没有错误但仍然弹性上没有数据?

来自 elastic 的调试信息:POST 上的成功低级调用:/abc/abc/_bulk?error_trace=true&amp;refresh=true

如果有人能提供任何线索我在这里做错了什么会非常有帮助?

【问题讨论】:

    标签: c# elasticsearch


    【解决方案1】:

    通过在每个不需要逗号的记录集之后修改输入 JSON 格式来解决这个问题:

    {"index":{"_index":"abc","_type":"abc","_id":1}}{"Name":"ApplicationFrameHost","CPU":1.25,"Company":null,"Product":null,"Path":null}{"index":{"_index":"abc","_type":"abc","_id":2}},{"Name":"audiodg","CPU":1.5625,"Company":null,"Product":null,"Path":null}{"index":{"_index":"abc","_type":"abc","_id":3}},{"Name":"Calculator","CPU":0.5,"Company":null,"Product":null,"Path":null}{"index":{"_index":"abc","_type":"abc","_id":4}},{"Name":"chrome","CPU":144.109375,"Company":null,"Product":null,"Path":null}{"index":{"_index":"abc","_type":"abc","_id":5}},{"Name":"chrome","CPU":3384.609375,"Company":null,"Product":null,"Path":null}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-20
      • 2013-10-16
      • 1970-01-01
      • 1970-01-01
      • 2021-08-16
      • 1970-01-01
      • 2014-12-09
      • 2021-01-01
      相关资源
      最近更新 更多