You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
2.0 KiB
C#
72 lines
2.0 KiB
C#
using Elastic.Transport;
|
|
using Elastic.Transport.Diagnostics;
|
|
using Elastic.Transport.Extensions;
|
|
using Elastic.Transport.Products;
|
|
|
|
using Elastic.Clients.Elasticsearch;
|
|
using Xunit.Abstractions;
|
|
using ElasticSearchStudy.Core;
|
|
|
|
namespace ElasticSearchStudy.UnitTest
|
|
{
|
|
public class UseElasticSearchTest
|
|
{
|
|
private readonly ITestOutputHelper _output;
|
|
private readonly ElasticsearchClient _client;
|
|
|
|
public UseElasticSearchTest(ITestOutputHelper outputHelper)
|
|
{
|
|
_output = outputHelper;
|
|
|
|
var elasticSetting = new ElasticsearchClientSettings(new Uri("https://localhost:9200"))
|
|
.CertificateFingerprint("F8:B0:ED:80:2C:1C:6C:76:6E:CC:21:3A:CD:91:C3:C8:C7:77:D4:41:F4:71:50:FB:E7:0E:66:0D:71:8C:F3:1A")
|
|
.Authentication(new BasicAuthentication("elastic", "3JI3QjRtjW8-Tl1q=mVx"));
|
|
|
|
_client = new ElasticsearchClient(elasticSetting);
|
|
}
|
|
|
|
[Fact]
|
|
public void ES_Ping_Test()
|
|
{
|
|
var pingResponse = _client.Ping();
|
|
|
|
if (pingResponse.IsSuccess())
|
|
{
|
|
_output.WriteLine($"ÇëÇó³É¹¦,{pingResponse.DebugInformation}");
|
|
}
|
|
else
|
|
{
|
|
_output.WriteLine("ÇëÇóʧ°Ü");
|
|
}
|
|
|
|
Assert.True(pingResponse.IsSuccess());
|
|
}
|
|
|
|
[Fact]
|
|
public void CreateIndex_Test()
|
|
{
|
|
_client.Ping();
|
|
var dd = _client.Cluster;
|
|
|
|
}
|
|
|
|
[Fact]
|
|
public void GetDoc_Test()
|
|
{
|
|
var tweet = new Tweet
|
|
{
|
|
Id = 2,
|
|
User = "stevejgordon",
|
|
PostDate = new DateTime(2009, 11, 15),
|
|
Message = "Trying out the client, so far so good?"
|
|
};
|
|
|
|
var response = _client.Create<Tweet>(tweet, "my-tweet-index",3);
|
|
|
|
if (response.IsValidResponse)
|
|
{
|
|
_output.WriteLine($"Index document with ID {response.Id} succeeded.");
|
|
}
|
|
}
|
|
}
|
|
} |