mirror of
				https://github.com/gnh1201/welsonjs.git
				synced 2025-10-31 04:51:17 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			31 lines
		
	
	
		
			890 B
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			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);
 | |
|         }
 | |
|     }
 | |
| }
 |