VOOZH about

URL: https://www.nuget.org/packages/Galosys.Foundation.Elastic/

⇱ NuGet Gallery | Galosys.Foundation.Elastic 26.5.20.1




Galosys.Foundation.Elastic 26.5.20.1

dotnet add package Galosys.Foundation.Elastic --version 26.5.20.1
 
 
NuGet\Install-Package Galosys.Foundation.Elastic -Version 26.5.20.1
 
 
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Galosys.Foundation.Elastic" Version="26.5.20.1" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Galosys.Foundation.Elastic" Version="26.5.20.1" />
 
Directory.Packages.props
<PackageReference Include="Galosys.Foundation.Elastic" />
 
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Galosys.Foundation.Elastic --version 26.5.20.1
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Galosys.Foundation.Elastic, 26.5.20.1"
 
 
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Galosys.Foundation.Elastic@26.5.20.1
 
 
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Galosys.Foundation.Elastic&version=26.5.20.1
 
Install as a Cake Addin
#tool nuget:?package=Galosys.Foundation.Elastic&version=26.5.20.1
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Galosys.Foundation.Elastic

成熟度: 🟡 可用 — 功能完整,测试或文档可能不完善

简介

Galosys.Foundation.Elastic 是对 Elasticsearch 8.0 客户端的封装,提供基于 Microsoft.Extensions.DependencyInjection 的依赖注入支持,简化在 .NET 应用中集成 Elasticsearch 的配置和使用。

特性

  • 支持 Elasticsearch 8.0 客户端
  • 支持单节点和多节点集群配置
  • 支持基本认证(用户名/密码)
  • 基于 Microsoft.Extensions.DependencyInjection 的依赖注入
  • 通过 IOptions 模式进行配置管理
  • 支持请求超时配置

安装

dotnet add package Galosys.Foundation.Elastic

配置

1. 添加配置文件

appsettings.json 中添加 Elasticsearch 配置:

{
 "Elasticsearch": {
 "Uris": [ "http://localhost:9200" ],
 "UserName": "your-username",
 "Password": "your-password"
 }
}

使用

1. 注册服务

Program.csStartup.cs 中注册 Elasticsearch 服务:

using Microsoft.Extensions.DependencyInjection;

var builder = WebApplication.CreateBuilder(args);

// 添加 Elasticsearch 服务
builder.Services.AddElastic8_0();

var app = builder.Build();

基本操作

索引文档
var product = new Product { Id = "1", Name = "示例产品", Price = 99.99m };
var response = await _client.IndexAsync(product, idx => idx
 .Index("products")
 .Id(product.Id));
获取文档
var response = await _client.GetAsync<Product>("1", g => g.Index("products"));
if (response.IsSuccess)
{
 var product = response.Source;
}
删除文档
var response = await _client.DeleteAsync("products", "1");

搜索

基本搜索
var response = await _client.SearchAsync<Product>(s => s
 .Index("products")
 .Query(q => q
 .Match(m => m
 .Field(f => f.Name)
 .Query("示例")
 )
 )
);

foreach (var product in response.Documents)
{
 Console.WriteLine(product.Name);
}
高级搜索
var response = await _client.SearchAsync<Product>(s => s
 .Index("products")
 .Query(q => q
 .Bool(b => b
 .Must(m => m
 .Match(t => t
 .Field(f => f.Name)
 .Query("示例")
 )
 )
 .Filter(f => f
 .Range(r => r
 .NumberRange(n => n
 .Field(f => f.Price)
 .Gte(50)
 .Lte(200)
 )
 )
 )
 )
 )
 .Size(10)
 .From(0)
 .Sort(so => so
 .Field(f => f.Price, f => f.Order(SortOrder.Asc))
 )
);

核心类

说明
ElasticsearchClient Elasticsearch 8.0 客户端实例,用于执行索引、搜索等操作
ElasticsearchOptions 配置选项类,包含 Uris、UserName、Password 属性
ElasticServiceCollectionExtensions 依赖注入扩展类,提供 AddElastic8_0() 方法
ElasticModule 内部模块类,实现 IModule 接口用于自动注册

依赖

注意事项

  1. 请求超时默认设置为 2 分钟
  2. 支持单节点和多节点集群自动配置
  3. 认证方式支持基本认证(BasicAuthentication)
  4. 异常处理:配置错误时会抛出 ArgumentNullException
  5. 客户端注册为单例模式,线程安全
Product Versions Compatible and additional computed target framework versions.
.NET net8.0 net8.0 is compatible.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 was computed.  net9.0-android net9.0-android was computed.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  net10.0 net10.0 was computed.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Galosys.Foundation.Elastic:

Package Downloads
Galosys.NETCore.Base

Galosys.Foundation快速开发库

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
26.5.20.1 96 5/20/2026
26.5.19.1 102 5/19/2026
26.5.18.1 97 5/18/2026
26.5.15.1 89 5/15/2026
26.5.12.3 89 5/12/2026
26.5.12.2 93 5/12/2026
26.4.27.1-rc1 92 4/26/2026
26.4.25.1-rc1 90 4/25/2026
26.4.22.2-rc7 102 4/22/2026
26.4.22.2-rc6 92 4/22/2026
26.4.22.2-rc4 97 4/22/2026
26.4.22.2-rc3 94 4/22/2026
26.4.19.1-rc1 98 4/19/2026
26.4.12.8-rc1 115 4/12/2026
26.4.12.7-rc1 111 4/12/2026
26.4.12.5-rc1 95 4/12/2026
26.1.30.1-rc1 133 1/30/2026
26.1.29.1 137 1/29/2026
26.1.28.5 127 1/28/2026
26.1.28.4 130 1/28/2026
Loading failed