【问题标题】:How to Index Json Data using NEST Client for Elastic Search?如何使用 NEST 客户端为弹性搜索索引 Json 数据?
【发布时间】:2021-02-10 00:01:35
【问题描述】:

我正在尝试使用 C# NEST 库将 json 字符串文件索引到 Elastic Search。我发现这个post 是相关的。但是.Index<string>有语法错误

var indexResponse = _elasticClient.LowLevel.Index<string>("index-name", "type-name", json);

错误是

类型“string”不能用作类型参数“TResponse” 泛型类型或方法 'IElasticLowLevelClient.Index(字符串,字符串,PostData, 索引请求参数)'。没有隐式引用转换 来自“字符串”

【问题讨论】:

    标签: c# nest


    【解决方案1】:

    看看low level client documentation

    var pool = new SingleNodeConnectionPool(new Uri($"http://localhost:9200"));
    var settings = new ConnectionSettings(pool);
        
    var client = new ElasticClient(settings);
    
    var person = @"{ ""first_name"": ""Russ"", ""last_name"": ""Cam"" }";
    
    var indexResponse = client.LowLevel.Index<StringResponse>("people", "1", person);
    string responseString = indexResponse.Body;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-05-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多