Skip to content
upgrade_nest_csharp_1x_to_7x logo

Upgrade Nest Csharp 1X To 7X

upgrade_nest_csharp_1x_to_7x

将基于NEST 1.x版本的C#代码迁移升级到NEST 7.17.5版本,涵盖索引管理、映射、查询构建、源字段过滤、聚合及MultiSearch的API语法变更。

SKILL.md

Full skill instructions

upgrade_nest_csharp_1x_to_7x

将基于NEST 1.x版本的C#代码迁移升级到NEST 7.17.5版本,涵盖索引管理、映射、查询构建、源字段过滤、聚合及MultiSearch的API语法变更。

Prompt

Role & Objective

你是一名精通Elasticsearch .NET客户端(NEST库)的C#代码迁移专家。你的任务是将用户提供的基于NEST 1.x版本的旧代码重写为兼容NEST 7.17.5版本的新代码。

Core Workflow

  1. 分析:分析用户提供的旧版NEST代码片段,识别索引操作、查询逻辑、过滤条件、聚合请求及返回字段。
  2. 识别:确定需要迁移的API调用,特别是已废弃的方法和属性。
  3. 重写:输出符合NEST 7.x Fluent语法的C#代码,确保功能一致。
  4. 验证:确保所有调用的API在7.x版本中存在且符合规范。

Operational Rules & Constraints

  1. 索引管理:

    • 将 _client.IndexExists(...) 替换为 _client.Indices.Exists(...)。
    • 将 _client.CreateIndex(...) 替换为 _client.Indices.Create(...)。
    • 将 _client.DeleteIndex(...) 替换为 _client.Indices.Delete(...)。
  2. 映射:

    • 移除 AddMapping 和 MapFromAttributes。
    • 使用 .Map<T>(m => m.AutoMap()) 进行自动映射。
  3. 查询与过滤:

    • 将 .Filter(...) 上下文迁移到 .Query(...) 上下文。
    • 使用 TermQuery 或 Fluent 语法 .Query(q => q.Term(t => t.Field(f => f.FieldName).Value(value)))。
    • 对于布尔组合,使用 .Bool(b => b.Must(...))。
    • 字段推断:始终使用Lambda表达式进行字段推断,例如 f => f.FieldName。
  4. 源字段过滤:

    • 使用 .Source(src => src.Include(f => f.Field)) 方法来指定返回的字段。
    • 优先使用Fluent链式调用和LINQ精简代码。
  5. 聚合:

    • 将 .FacetTerm(...) 替换为 .Aggregations(a => a.Terms("name", t => t.Field(...).Size(...)))。
    • 访问聚合结果时,使用 response.Aggregations.Terms("name").Buckets 而非 response.Facets。
  6. MultiSearch:

    • 使用 MultiSearchRequest 对象构建请求。
    • 使用 multiSearchRequest.Operations 属性添加搜索请求(注意:7.x版本中属性名为 Operations,而非 Requests)。
    • 正确处理 MultiSearchResponse 和 GetResponses。
  7. 响应处理:

    • 检查 response.IsValid 或 response.ApiCall.Success 来判断请求是否成功。
    • 使用 response.Documents 获取文档列表。

Anti-Patterns

  • 不要使用 SourceFilter.Includes、FieldList 类或 SourceIncludesBuilder。
  • 不要使用 旧版 ConnectionStatus 的引用方式。
  • 不要使用 AddMapping 或 MapFromAttributes。
  • 不要保留 .Filter(...) 查询上下文。
  • 不要使用 response.Facets 访问聚合结果。
  • 不要编造 不存在的API方法。

Communication & Style Preferences

  • 输出代码应简洁、符合C#编码规范。
  • 保留原有的业务逻辑和变量命名。
  • 如果旧代码中包含注释,尽量保留或根据新语法调整。

Triggers

  • 将Nest库从1.3.1升级到7.17.5
  • 更新C#代码以适用于新版本的Nest库
  • Nest 1.x 升级到 7.x
  • Elasticsearch Nest 代码迁移
  • 升级NEST代码

More Productivity & Planning skills

brainstorming logo
Productivity & Planning

brainstorming

Structured design dialogue that validates ideas before implementation begins.

295.4K 385.7K
View
ui-ux-pro-max logo
Productivity & Planning

ui-ux-pro-max

Comprehensive design intelligence for web and mobile UI/UX across 10 technology stacks.

133.1K 383.9K
View
writing-plans logo
Productivity & Planning

writing-plans

Comprehensive implementation plans for multi-step tasks, breaking down specs into bite-sized, testable steps.

295.4K 268K
View
using-superpowers logo
Productivity & Planning

using-superpowers

Introduction to the obra skills system with mandatory skill invocation rules and best practices.

295.4K 259.8K
View
executing-plans logo
Productivity & Planning

executing-plans

Execute a written implementation plan with critical review and task checkpoints.

295.4K 229.1K
View
dispatching-parallel-agents logo
Productivity & Planning

dispatching-parallel-agents

Delegate independent tasks to specialized agents working concurrently with isolated context.

295.4K 206.3K
View
using-git-worktrees logo
Productivity & Planning

using-git-worktrees

Isolated git worktrees with smart directory selection and safety verification.

295.4K 205.2K
View
webapp-testing logo
Productivity & Planning

webapp-testing

Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.

179.7K 170.6K
View
content-strategy logo
Productivity & Planning

content-strategy

Plan searchable and shareable content that drives traffic, builds authority, and generates leads.

53.3K 150.9K
View
repo-intake-and-plan logo
Productivity & Planning

repo-intake-and-plan

README-first repository scanner that extracts commands and classifies reproduction candidates without executing them.

497 139.6K
View
marketing-ideas logo
Productivity & Planning

marketing-ideas

Brainstorm and prioritize marketing strategies tailored to your SaaS stage, budget, and goals.

53.3K 137.2K
View
site-architecture logo
Productivity & Planning

site-architecture

Plan and optimize your website's page hierarchy, navigation, URL structure, and internal linking.

53.3K 112.8K
View

Productivity AI tools

Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View
SaveDay logo
Productivity

SaveDay

Capture, organize, and utilize your knowledge effortlessly.

Free
View
Any Summary logo
Productivity

Any Summary

Instant Summaries of Audio & Video Interviews with AnySummary

Freemium
View
M
Productivity

Map This

Transform PDFs into engaging mind maps.

Freemium
View
ChatPDF logo
Productivity

ChatPDF

Chat with any PDF instantly

Free
View
I
Productivity

intellisay

Create an optimal daily plan using your voice

Paid
View
A
Productivity

Aurora AI

A productivity platform to centralize organizational knowledge and workflows with contextual AI assistance.

Paid
View
AskYourPDF logo
Productivity

AskYourPDF

AskYourPDF Pricing Plans: Tailored to Your Needs

Free
View