welsonjs/WelsonJS.Augmented/WelsonJS.Service/ElasticsearchClient.cs
Namhyeon, Go fdabeab54f Change the project name to WelsonJS.Toolkit to WelsonJS.Augmented
Change the project name to WelsonJS.Toolkit to WelsonJS.Augmented
2025-12-14 18:54:32 +09:00

31 lines
890 B
C#

// ElasticsearchClient.cs
// https://github.com/gnh1201/welsonjs
using RestSharp.Authenticators;
using RestSharp;
namespace WelsonJS.Service
{
public class ElasticsearchClient
{
private readonly RestClient client;
public ElasticsearchClient(string baseUrl, string username, string password)
{
var options = new RestClientOptions(baseUrl)
{
Authenticator = new HttpBasicAuthenticator(username, password)
};
client = new RestClient(options);
}
public RestResponse IndexDocument(string indexName, object document)
{
var request = new RestRequest($"/{indexName}/_doc", Method.Post);
request.AddHeader("Content-Type", "application/json");
request.AddJsonBody(document);
return client.Execute(request);
}
}
}