CommunityCoding & Developmentgithub.com

Zoha/agent-skills

Use when adding or maintaining Elasticsearch full-text search in a NestJS backend — client and module wiring, MongoDB-to-Elasticsearch sync and reindexing, index mappings and the search projection, ID-only queries with MongoDB hydration, cursor pagination, cross-entity derived fields, making search optional through a configurable backend seam, and testing search with a mocked seam or a real throwaway cluster.

What is agent-skills?

agent-skills is a Cursor agent skill that use when adding or maintaining Elasticsearch full-text search in a NestJS backend — client and module wiring, MongoDB-to-Elasticsearch sync and reindexing, index mappings and the search projection, ID-only queries with MongoDB hydration, cursor pagination, cross-entity derived fields, making search optional through a configurable backend seam, and testing search with a mocked seam or a real throwaway cluster.

Works with~Claude Code~Codex CLI✓Cursor
npx skills add https://github.com/Zoha/agent-skills/tree/HEAD/skills/nestjs-elasticsearch

Installed? Explore more Coding & Development skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

Ask in your favorite AI

Open a new chat with this agent skill pre-loaded.

Documentation

NestJS Elasticsearch

Integration guide for adding Elasticsearch-backed search to a NestJS GraphQL + MongoDB application. It fixes the architectural boundary (generic infra, a shared search layer, one owned index per feature), then covers the full lifecycle: the search projection, indexing and sync, ID-only querying with MongoDB hydration, cursor pagination, cross-entity derived fields, running with search optional via a configurable backend seam, testing without a live cluster, and the operations and DX around all of it.

The guiding contract is Elasticsearch finds, MongoDB serves: Elasticsearch is a pure search index that returns identifiers, and the requested entities are always hydrated from MongoDB, the source of truth.

When to Apply

Reference these guidelines when:

  • Adding search to an existing NestJS GraphQL + MongoDB application
  • Wiring the @nestjs/elasticsearch client and the shared search layer
  • Defining or changing an index mapping or the search projection
  • Implementing MongoDB-to-Elasticsearch sync, reindexing, or index migrations
  • Writing a search query, cursor pagination, or result hydration
  • Keeping a derived value (counts, ratings) searchable across entities
  • Making search optional, or swapping the backend, from configuration without a cluster
  • Testing search with a mocked backend seam, or against a real throwaway cluster
  • Debugging stale search results or indexing storms

Rule Categories by Priority

PriorityCategoryImpactPrefix
1ArchitectureCRITICALarch-
2Indexing & SyncCRITICALsync-
3Schema & MappingHIGHmap-
4QueryingHIGHquery-
5Cross-EntityMEDIUM-HIGHrel-
6Operations & DXMEDIUMops-
7Configuration & EnvironmentsHIGHcfg-
8TestingMEDIUM-HIGHtest-

Quick Reference

1. Architecture (CRITICAL)

  • arch-base-search-repository - Put Shared Index and Query Logic in a Base Repository
  • arch-entity-vs-search-document - Keep Elasticsearch Fields Out of the Entity
  • arch-feature-owned-index - Let Each Feature Own and Register Its Index
  • arch-infra-module - Isolate the Elasticsearch Client in a Generic Infra Module

2. Indexing & Sync (CRITICAL)

  • sync-bulk-index - Index in Batches with the Bulk API
  • sync-debounce-same-id - Debounce Same-Id Bursts
  • sync-delete-immediately - Delete from the Index Immediately
  • sync-enqueue-index - Enqueue Indexing; Never Write to Elasticsearch Inline
  • sync-full-reindex-alias-swap - Reindex Through a Versioned Index and Swap the Alias
  • sync-idempotent-index-creation - Create Indices Idempotently with Deterministic Names

3. Schema & Mapping (HIGH)

  • map-analyzers - Choose Text Analyzers Deliberately
  • map-derived-fields - Compute Derived and Relation Fields in a Batch Mapper
  • map-exclude-non-search-fields - Index Only Fields With a Search Purpose
  • map-mapping-object - Declare the Mapping as a Typed Object
  • map-typed-search-document - Type the Search Document Against the Entity

4. Querying (HIGH)

  • query-cursor-pagination - Paginate with search_after
  • query-hydrate-restore-order - Hydrate from MongoDB and Restore Relevance Order
  • query-ids-only-search - Search Returns IDs Only
  • query-sort-tiebreaker - Always Include a Unique Sort Tiebreaker

5. Cross-Entity (MEDIUM-HIGH)

  • rel-derived-counter-cache - Cache Derived Counters on the Owning Document
  • rel-owning-module-subscribes - The Owning Module Subscribes; Others Emit Their Own Events

6. Operations & DX (MEDIUM)

  • ops-cli-scripts - Provide Migration and Reindex CLI Commands
  • ops-explain-debug - Provide an Explain Hook
  • ops-health-check - Include Elasticsearch in Health Checks
  • ops-log-es-requests - Log Elasticsearch Requests and Responses
  • ops-no-cron-for-indexing - Never Schedule Indexing with an In-Process Timer

7. Configuration & Environments (HIGH)

  • cfg-mongo-fallback-backend - Fall Back to a Deterministic MongoDB Finder
  • cfg-search-backend-seam - Put Search Behind a Backend Seam

8. Testing (MEDIUM-HIGH)

  • test-mock-elasticsearch-seam - Mock the Search Backend Seam in Unit Tests
  • test-real-es-for-query-semantics - Test Query Semantics Against a Real Elasticsearch

How to Use

Read individual rule files for detailed explanations and code examples:

rules/arch-entity-vs-search-document.md
rules/sync-full-reindex-alias-swap.md
rules/query-ids-only-search.md

Each rule file contains:

  • Brief explanation of why it matters and which layer it applies to
  • Incorrect code example with explanation
  • Correct code example with explanation
  • Additional context and references

Relation to Other Skills

  • nestjs-graphql-structure — file placement. This skill adds the search/ folder to a feature and the common/search/ + infra/elasticsearch/ layers; it follows that skill's feature-module, repository, and event rules.
  • nestjs-best-practices — behavioral rules for services, events, queues, config, and health checks that this skill's examples build on.
  • One deliberate exception — nestjs-graphql-structure's service-background-jobs rule keeps processors in the owning feature. The search pipeline runs once in common/search/ and resolves each feature's repository through the index registry instead, because the pipeline is identical for every feature; see arch-base-search-repository.

Full Compiled Document

For the complete guide with all rules expanded in a single document, see AGENTS.md.

Individual skills in this repo

This repo contains 2 individual skills — each has its own dedicated page.

Zoha/agent-skills

Application structure and file-placement guide for NestJS GraphQL (code-first) applications. Use when deciding where a file belongs, designing or reviewing a feature-first directory layout, scaffolding a new feature module, or working out how modules connect to resolve GraphQL fields and relations. Covers the base structure map plus per-file rules for modules, services, resolvers (query, mutation, subscription, field), inputs and args, pagination, entities (Mongoose schema best practices for shared types), repository-only model injection, models/mappers, repositories, Mongoose discriminators, derived fields, providers, loaders, events, background jobs, auth, exceptions, custom scalars, config, common building blocks, infra setup, and the naming/testing/lint conventions — and module-resolution concerns such as circular dependencies. For behavioral rules (DI depth, security, performance, error handling) use the nestjs-best-practices skill instead.

Zoha/agent-skills

Use when caching GraphQL reads in a NestJS (code-first) app — wiring a stale-while-revalidate (SWR) cache module once, deciding what to cache and where to mount it (service, field, operation, or CDN), and keeping it leak-safe. Triggers when you need SWR, single-flight dedupe, tag invalidation, per-user vs public scoping, cache observability, a stampede or blocking-miss at TTL expiry, a shared-key data leak, a dev/ops switch that disables caching entirely, or a one-time setup reference (module, file placement, storage, referencesTTL/GC, caller identity, decorator runtime, fail-open).

Related Skills