add: 添加项目

main
bicijinlian 2 years ago
parent 33550302ba
commit 297ee21dd8

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\ElasticSearchStudy.Core\ElasticSearchStudy.Core.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,10 @@
namespace ElasticSearchStudy.App
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
}
}
}

@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Elastic.Clients.Elasticsearch" Version="8.0.8" />
</ItemGroup>
</Project>

@ -0,0 +1,12 @@
using System;
namespace ElasticSearchStudy.Core
{
public class Tweet
{
public int Id { get; set; }
public string User { get; set; }
public DateTime PostDate { get; set; }
public string Message { get; set; }
}
}

@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ElasticSearchStudy.Core\ElasticSearchStudy.Core.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,97 @@
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 ITestOutputHelper _output;
public UseElasticSearchTest(ITestOutputHelper outputHelper)
{
_output = outputHelper;
}
[Fact]
public void Test()
{
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"));
ElasticsearchClient client = new ElasticsearchClient(elasticSetting);
var pingResponse = client.Ping();
if (pingResponse.IsSuccess())
{
_output.WriteLine($"ÇëÇó³É¹¦,{pingResponse.DebugInformation}");
}
else
{
_output.WriteLine("ÇëÇóʧ°Ü");
}
Assert.True(pingResponse.IsSuccess());
}
[Fact]
public void CreateIndex_Test()
{
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"))
;
ElasticsearchClient client = new ElasticsearchClient(elasticSetting);
var tweet = new Tweet
{
Id = 1,
User = "stevejgordon",
PostDate = DateTime.Now,
Message = "Trying out the client, so far so good?"
};
var response = client.Index(tweet, "tweet-index");
if (response.IsValidResponse)
{
Console.WriteLine($"Index document with ID {response.Id} succeeded.");
}
}
[Fact]
public void GetDoc_Test()
{
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"));
ElasticsearchClient client = new ElasticsearchClient(elasticSetting);
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.");
}
}
}
}

@ -0,0 +1,37 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.33516.290
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ElasticSearchStudy.App", "ElasticSearchStudy.App\ElasticSearchStudy.App.csproj", "{215D6950-7B9F-4743-BD81-ACE3D7F1CAED}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ElasticSearchStudy.Core", "ElasticSearchStudy.Core\ElasticSearchStudy.Core.csproj", "{86F7481E-5EBB-45A9-8621-F2CAA486D73A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ElasticSearchStudy.UnitTest", "ElasticSearchStudy.UnitTest\ElasticSearchStudy.UnitTest.csproj", "{3008F5A9-43DA-48AF-883E-514FD71B65A2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{215D6950-7B9F-4743-BD81-ACE3D7F1CAED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{215D6950-7B9F-4743-BD81-ACE3D7F1CAED}.Debug|Any CPU.Build.0 = Debug|Any CPU
{215D6950-7B9F-4743-BD81-ACE3D7F1CAED}.Release|Any CPU.ActiveCfg = Release|Any CPU
{215D6950-7B9F-4743-BD81-ACE3D7F1CAED}.Release|Any CPU.Build.0 = Release|Any CPU
{86F7481E-5EBB-45A9-8621-F2CAA486D73A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{86F7481E-5EBB-45A9-8621-F2CAA486D73A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{86F7481E-5EBB-45A9-8621-F2CAA486D73A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{86F7481E-5EBB-45A9-8621-F2CAA486D73A}.Release|Any CPU.Build.0 = Release|Any CPU
{3008F5A9-43DA-48AF-883E-514FD71B65A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3008F5A9-43DA-48AF-883E-514FD71B65A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3008F5A9-43DA-48AF-883E-514FD71B65A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3008F5A9-43DA-48AF-883E-514FD71B65A2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8B5DC314-3806-4C06-ADF0-9342FE9F1DF0}
EndGlobalSection
EndGlobal
Loading…
Cancel
Save