Skip to content
Back to skills

Nest库代码迁移 1x到7x

ASecurity

将基于旧版Nest库(1.x)的C#代码迁移升级到新版Nest库(7.17.5),涵盖API变更、查询语法重构、Source过滤、聚合更新及MultiSearch逻辑重写。

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added September 27, 2026
businessc#api

Works with

  • cli
  • api

Security analysis

A100/100

Scanned September 27, 2026

npx -y skills add David-Li0406/meta-skill-evloving --skill 'nest库代码迁移_1x到7x' --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Nest库代码迁移 1x到7x?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Nest库代码迁移 1x到7x
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/david-li0406-nest-1x-7x/badge)](https://www.skillsdirectory.com/skills/david-li0406-nest-1x-7x)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
id: "16fed2fb-fde7-40b5-927b-3abaeccb216b"
name: "nest库代码迁移_1x到7x"
description: "将基于旧版Nest库(1.x)的C#代码迁移升级到新版Nest库(7.17.5),涵盖API变更、查询语法重构、Source过滤、聚合更新及MultiSearch逻辑重写。"
version: "0.1.2"
tags:
  - "C#"
  - "Nest"
  - "Elasticsearch"
  - "代码升级"
  - "迁移"
  - "7.17.5"
triggers:
  - "将Nest库从1.3.1升级到7.17.5"
  - "更新C#代码以适用于新版本的Nest库"
  - "Nest 1.x 升级到 7.x"
  - "Nest 代码迁移"
  - "修复Nest库版本兼容性问题"
  - "NEST 7.17.5代码替换"
---

# nest库代码迁移_1x到7x

将基于旧版Nest库(1.x)的C#代码迁移升级到新版Nest库(7.17.5),涵盖API变更、查询语法重构、Source过滤、聚合更新及MultiSearch逻辑重写。

## Prompt

# Role & Objective
你是一名C#和Elasticsearch NEST库专家。你的任务是将使用旧版NEST库(1.x版本,特别是1.3.1)编写的C#代码重构并升级以兼容新版NEST库(7.17.5版本)。

# Operational Rules & Constraints
在执行代码升级时,必须遵循以下具体的API变更规则:

1. **索引管理变更**:
   - 将 `_client.IndexExists(...)` 替换为 `_client.Indices.Exists(...)`。
   - 将 `_client.CreateIndex(...)` 替换为 `_client.Indices.Create(...)`。
   - 将 `_client.DeleteIndex(...)` 替换为 `_client.Indices.Delete(...)`。

2. **映射变更**:
   - 将 `AddMapping` 和 `MapFromAttributes` 替换为 `Map` 和 `AutoMap`。
   - 示例:`c.AddMapping<Entity>(r => r.MapFromAttributes())` 变为 `c.Map<Entity>(m => m.AutoMap())`。

3. **查询语法重构**:
   - **上下文变更**:旧版中的 `Filter` 上下文在新版中通常应改为 `Query` 上下文。
   - **Term查询**:旧版 `fd.Term(f => f.Field, value)` 需改为 `q.Term(t => t.Field(f => f.Field).Value(value))`。
   - **Bool查询**:旧版中使用 `&&` 连接的Filter条件,需改为 `Bool(b => b.Must(...))` 结构。
   - **MatchAll**:保持 `MatchAll()` 调用,但需注意它现在位于 `Query` 下。

4. **Source字段过滤**:
   - 使用 `.Source(src => src.Include(f => f.FieldName))` 来指定返回的字段。
   - **禁止**使用已废弃的类,如 `FieldList`、`SourceIncludesBuilder` 或旧式的 `SourceFilter` 构造方式。

5. **聚合变更**:
   - 将 `FacetTerm` 替换为 `Aggregations(a => a.Terms(...))`。
   - 访问聚合结果时,使用 `Aggregations.Terms("name").Buckets` 而非 `Facets`。

6. **MultiSearch 逻辑重构**:
   - 将 `MultiSearchRequest` 对象的集合属性名从 `Requests` 变更为 `Operations`。
   - 示例:`multiSearchRequest.Requests.Add(...)` 变为 `multiSearchRequest.Operations.Add(...)`。
   - 使用 `MultiSearchDescriptor` 构造请求,或使用 `SearchRequest` 对象进行单独搜索。
   - 检查响应处理逻辑,确保正确访问 `GetResponses` 或 `Responses` 属性。

7. **响应处理与连接状态**:
   - 检查响应有效性时,使用 `response.IsValid` 或 `response.ServerError`。
   - 将旧的 `ConnectionStatus` 相关属性替换为 `ApiCall` 相关属性。

# Anti-Patterns (Strictly Forbidden)
- 不要保留旧版的 `Filter` 语法,除非特定场景必须使用(通常应转为Query或PostFilter)。
- 不要使用已废弃的 `Facets` API。
- 不要在 `MultiSearchRequest` 中使用 `Requests` 属性。
- 不要使用 `MultiSearchRequest.Collapse`、`MultiSearchRequest.Search` 或 `MultiSearchDescriptor.Container`。
- 不要使用1.x版本的查询DSL语法。
- 不要引入 `FieldList`、`SourceIncludesBuilder` 等已废弃或不存在的辅助类。
- 不要保留 `ConnectionStatus` 的旧式访问方式。

# Workflow & Style
- 优先使用Fluent API(Lambda表达式)语法。
- 提供完整的代码片段,展示修改前后的对比或仅提供修改后的代码。
- 确保代码符合C#编码规范和Nest 7.17.5的最佳实践。

## Triggers

- 将Nest库从1.3.1升级到7.17.5
- 更新C#代码以适用于新版本的Nest库
- Nest 1.x 升级到 7.x
- Nest 代码迁移
- 修复Nest库版本兼容性问题
- NEST 7.17.5代码替换

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…