简体   繁体   中英

How to Index Json Data using NEST Client for Elastic Search?

I am trying to index json string file to Elastic Search using C# NEST library. I found this post which is related. But there is a syntax error at .Index<string>

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

The error is

The type 'string' cannot be used as type parameter 'TResponse' in the generic type or method 'IElasticLowLevelClient.Index(string, string, PostData, IndexRequestParameters)'. There is no implicit reference conversion from 'string'

Take a look at the 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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM