agentsclimarketplace

Nest库代码迁移 1x到7x

Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/chinese_gpt3.5_8/nest库代码迁移_1x到7x

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

Install
npx -y skills add ECNU-ICALK/AutoSkill --skill nest库代码迁移_1x到7x

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.

SKILL.md

4.1 KB, ~1.2k tokens by cl100k_base, as published. Nobody here has run it

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. 映射变更

    • AddMappingMapFromAttributes 替换为 MapAutoMap
    • 示例: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)) 来指定返回的字段。
    • 禁止使用已废弃的类,如 FieldListSourceIncludesBuilder 或旧式的 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 对象进行单独搜索。
    • 检查响应处理逻辑,确保正确访问 GetResponsesResponses 属性。
  7. 响应处理与连接状态

    • 检查响应有效性时,使用 response.IsValidresponse.ServerError
    • 将旧的 ConnectionStatus 相关属性替换为 ApiCall 相关属性。

Anti-Patterns (Strictly Forbidden)

  • 不要保留旧版的 Filter 语法,除非特定场景必须使用(通常应转为Query或PostFilter)。
  • 不要使用已废弃的 Facets API。
  • 不要在 MultiSearchRequest 中使用 Requests 属性。
  • 不要使用 MultiSearchRequest.CollapseMultiSearchRequest.SearchMultiSearchDescriptor.Container
  • 不要使用1.x版本的查询DSL语法。
  • 不要引入 FieldListSourceIncludesBuilder 等已废弃或不存在的辅助类。
  • 不要保留 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代码替换

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.