Skip to content
CAI
Software that uses CAICheck a score

toptal/chewy

69.5

Adequate · 19 September 2026

8.7k

lines of production code

Ruby

primary language

1

measurement over time

CAI band scale
CAI lens gauges

What this system is

This system is a Ruby gem that provides an object-document mapper for Elasticsearch, enabling applications to synchronize data models with search indexes. It supports modern Rails versions and Elasticsearch 8, offering features like asynchronous indexing via Sidekiq, zero-downtime index management, and a comprehensive search DSL with advanced query capabilities. The library includes robust testing utilities and rake tasks to facilitate development, deployment, and maintenance of search infrastructure.

How it got here

2013 — Chewy 8.4.1 architecture overhaul

17 changes.

This period focused on a major architectural shift from the legacy Chewy::Type model to a modern Index-centric design, introducing new components like the Search::Request DSL and Journal system. The work involved significant refactoring of field composition, index lifecycle management, and client handling to support Elasticsearch 8 and Ruby 3.2+, while removing deprecated APIs and legacy dependencies.

2014–2017 — Search DSL and indexing strategy overhaul

13 changes.

This period focused on a comprehensive refactoring of the search layer, introducing a new DSL with explicit parameter storages to support advanced Elasticsearch features like aggregations and KNN. Concurrently, the library expanded its indexing capabilities by adding asynchronous and atomic strategies via Active Job and Sidekiq, alongside improved rake tasks for index management. These architectural changes were accompanied by extensive test coverage for the new search components, parameter handling, and testing helpers.

2021–2026 — Import engine refactoring and test expansion

8 changes.

The import subsystem was significantly restructured into modular components like BulkBuilder and Routine, introducing configurable scope cleanup and batched processing capabilities. A new Delayed Sidekiq strategy was added to optimize high-volume reindexing by batching updates in Redis. Comprehensive test suites were implemented across the import engine, adapter hierarchy, and index actions to ensure robustness.

Features

Added Rails generator for Chewy configuration

A new Rails generator has been added to simplify the setup of Chewy. Running the generator creates a \config/chewy.yml\ file with default environment-specific settings, including Elasticsearch hosts for development (localhost:9200) and test (localhost:9250) environments.

lib/generators · high confidence

Chewy 8.4.1: Major architecture overhaul and new features

Chewy has been upgraded to version 8.4.1, introducing a significant architectural shift from the legacy \Chewy::Type\ model to a modern \Chewy::Index\-centric design. This release removes the deprecated \Chewy::Query\ class in favor of the new \Chewy::Search::Request\ DSL, which provides a more robust and chainable interface for building queries. New capabilities include a \Chewy::MultiSearch\ interface for executing multiple queries via the Elasticsearch Multi Search API, a \Chewy::Journal\ system for tracking and applying index changes over time, and a \Chewy::Repository\ for managing custom analyzers and filters. The update also refactors the internal client handling with \Chewy::ElasticClient\ to better manage connections and adds new rake tasks for zero-downtime index management (\reset\, \upgrade\, \sync\).

lib/chewy · high confidence

Introduce delayed Sidekiq strategy for batched reindexing

Adds a new \DelayedSidekiq\ strategy that accumulates reindex requests in Redis over a configurable latency window and processes them in batches via Sidekiq workers. This allows multiple index updates to be grouped together, reducing the number of individual reindex jobs and improving efficiency for high-volume updates.

_lib/chewy/strategy/delayed\sidekiq · high confidence

New Minitest helpers for mocking Elasticsearch and asserting index changes

Added \lib/chewy/minitest/helpers.rb\ and \lib/chewy/minitest/search\_index\_receiver.rb\ to provide testing utilities for Chewy. The new \assert\_indexes\ method allows tests to verify that specific indices are updated during a code block, while \mock\_elasticsearch\_response\ and \mock\_elasticsearch\_response\_sources\ enable mocking Elasticsearch API responses for query testing. Additionally, \SearchIndexReceiver\ captures bulk indexing operations (creates and deletes) to allow granular assertions on what data was indexed or removed, and a teardown hook automatically drops indices between tests to prevent pollution.

lib/chewy/minitest · high confidence

New async and atomic indexing strategies for Chewy

The library introduces several new indexing strategies to control how and when Elasticsearch updates occur. Users can now use \:active\_job\ and \:sidekiq\ strategies to perform asynchronous index updates via Active Job or Sidekiq workers, with configurable queues. A \:lazy\_sidekiq\ strategy is added to defer the evaluation of Chewy callbacks until a background job runs, while \:delayed\_sidekiq\ allows postponing index updates. Additionally, \:atomic\_no\_refresh\ provides an atomic update without forcing an index refresh, and \:urgent\ forces immediate updates on every save. These changes expand the options for balancing performance and consistency in index maintenance.

lib/chewy/strategy · high confidence

New parameter storage classes for Elasticsearch search options

The library introduces a comprehensive set of new parameter storage classes in \lib/chewy/search/parameters\ to support a wide range of Elasticsearch search features. These additions include storages for aggregations (\Aggs\), collapsing results (\Collapse\), highlighting (\Highlight\), and KNN search (\Knn\). It also adds support for source filtering (\Source\), stored fields (\StoredFields\), and docvalue fields (\DocvalueFields\), as well as boolean and integer parameters like \TrackTotalHits\, \MinScore\, \TerminateAfter\, and \Limit\. Additional features covered are \SearchAfter\ for pagination, \Rescore\ for result re-ranking, \RuntimeMappings\, \ScriptFields\, \Suggest\, and request-level options such as \Preference\, \Timeout\, \RequestCache\, and \IndicesBoost\. The \Filter\ and \PostFilter\ storages are also included to manage query contexts.

lib/chewy/search/parameters · high confidence

Removals

Removal of legacy Chewy::Type modules

The \Chewy::Type::Import\, \Chewy::Type::Mapping\, \Chewy::Type::Observe\, and \Chewy::Type::Wrapper\ modules have been removed from the codebase. This deletion eliminates the previous implementation details for type imports, field mappings, ActiveRecord observation hooks, and attribute wrapping, indicating a significant internal refactoring of how Chewy types are structured and how data is synchronized with Elasticsearch.

lib/chewy/type · high confidence

Behavioural changes

Enhanced RSpec matchers with atomic wrapping and strict filtering

The \update\_index\ RSpec matcher now defaults to wrapping index operations in an atomic strategy, ensuring that tests verify the final state of the index rather than intermediate bulk requests. It introduces an \.only\ chain method to enforce strict expectations, failing the test if any records are indexed or deleted beyond those explicitly specified via \and\_reindex\ or \and\_delete\. Additionally, the matcher now supports a \.no\_refresh\ chain to verify calls made with \refresh: false\, and includes new \build\_query\, \mock\_elasticsearch\_response\, and \mock\_elasticsearch\_response\_sources\ helpers to simplify query and response mocking in tests.

lib/chewy/rspec · high confidence

Kaminari pagination support moved to Search layer with new collection helper

Kaminari pagination integration has been relocated from the generic \Query\ class to the \Search::Request\ context, ensuring that pagination methods like \page\ and \per\ now apply specifically to search requests rather than all queries. The implementation now exposes a \paginated\_collection\ helper method, allowing users to easily convert raw result arrays into Kaminari-paginated collections with correct limit, offset, and total count metadata.

lib/chewy/search/pagination · high confidence

Major index architecture overhaul with compiled compose path and zero-downtime reset

The index module has been significantly restructured to improve performance and deployment safety. Document composition now defaults to a new compiled path that generates optimized Ruby methods at runtime, offering better performance than the legacy Witchcraft parser without requiring external AST dependencies. Index lifecycle management has been enhanced with new \create!\ and \delete!\ methods that support index suffixes for zero-downtime resets, allowing safe mapping changes without downtime. The import system now supports parallel processing, progress bars, and optional journaling for data consistency. Additionally, the library has dropped support for Elasticsearch 6.x, upgraded to Elasticsearch 8 client compatibility, and removed obsolete \\_type\ field references.

lib/chewy/index · high confidence

Major refactor of field composition and mapping generation

The field definition system has been significantly restructured to improve flexibility and correctness. Field initialization now uses keyword arguments, and the internal state management for options, children, and join-specific settings has been consolidated. The \compose\ method now supports passing multiple objects (including crutches and context) to value procs, enabling more dynamic data transformation. Mapping generation (\mappings\_hash\) has been rewritten to correctly handle nested fields, multi-fields, and default field types, ensuring proper Elasticsearch schema output. Additionally, the Root field now supports dynamic templates and explicit ID composition, allowing for more precise control over document indexing and JSON serialization.

lib/chewy/fields · high confidence

New and refactored Chewy rake tasks for index management

The \lib/tasks/chewy.rake\ file has been rewritten to provide a comprehensive set of Rake tasks for managing Elasticsearch indexes via the Chewy gem. This includes standard tasks for resetting, upgrading, updating, and synchronizing indexes, as well as a new \deploy\ task that combines upgrade and sync operations. A new \parallel\ namespace offers parallelized versions of these core tasks to improve performance, and a \journal\ namespace allows for manual journal creation, applying changes from a specific time, and cleaning up old journal records. The implementation delegates logic to \Chewy::RakeHelper\, supporting selective operations via command-line arguments.

lib/tasks · high confidence

New search DSL with dedicated parameter storages and loader

The search layer has been refactored to use a new DSL built around explicit parameter storages. \Chewy::Search::Parameters\ now manages request options (such as query, filter, limit, and offset) as distinct storage objects, allowing for more predictable merging and rendering of the Elasticsearch request body. \Chewy::Search::Request\ serves as the main entry point, delegating to these storages and exposing chainable methods for building queries. A new \Chewy::Search::Loader\ class handles the efficient loading of ORM/ODM objects from the database based on search hits, separating this concern from the request execution. Additionally, \Chewy::Search::Scrolling\ provides optimized batch iteration methods (\scroll\_batches\, \scroll\_objects\, etc.) that respect limits and properly clear scroll contexts, while \Chewy::Search::Response\ wraps the raw Elasticsearch response to provide convenient access to hits, wrappers, and loaded objects.

lib/chewy/search · high confidence

Project infrastructure modernized with RuboCop 1.84.2, Ruby 3.2+ target, and GitHub Actions CI

The repository has been updated to enforce modern code quality standards and CI practices. RuboCop has been upgraded to version 1.84.2, with a new \.rubocop.yml\ configuration targeting Ruby 3.2 and enabling the \rubocop-rake\ plugin. The continuous integration system has migrated from Travis CI to GitHub Actions, utilizing a Docker Compose setup to run Elasticsearch 8.19.13 and Redis 7 for testing. Additionally, legacy configuration files like \.travis.yml\ and \.rvmrc\ have been removed, and the project now requires Ruby \>= 3.2 and Rails \>= 7.2.

(repo-wide) · high confidence

Refactored core library structure and introduced runtime versioning

The library's internal structure has been significantly reorganized: the main entry point now explicitly requires specific Active Support extensions rather than the entire core\_ext bundle, and the monolithic type system has been replaced by a modular adapter-based architecture (Chewy::Index::Adapter). A new Chewy::Runtime::Version class has been added to handle semantic version comparison, and the global configuration storage has been migrated from fiber-local to thread-local variables via Chewy.current to better support multi-threaded environments. Additionally, the main module now exposes methods for managing Elasticsearch client lifecycle (close\_client) and cluster health (wait\_for\_status), while legacy error classes and the old derive\_type API have been removed in favor of the new derive\_name method.

lib · high confidence

Refactored import adapters with configurable scope cleanup

The import adapters for ActiveRecord and generic objects have been restructured into a new modular adapter hierarchy (Base, Orm, ActiveRecord, Object). A key behavioral change is that the cleanup of default index scope constraints (order, limit, offset) during import is now configurable via \Chewy.config.import\_scope\_cleanup\_behavior\, allowing users to choose between ignoring, warning, or raising an error when these constraints are present. The new ActiveRecord adapter implements batched importing and field plucking, while the Object adapter provides a generic fallback for non-ORM sources.

lib/chewy/index/adapter · high confidence

Refactored import engine with new bulk builder and progress bar

The import process has been restructured into dedicated components: BulkBuilder now handles the construction of Elasticsearch bulk requests (including join field support and partial updates), BulkRequest manages chunked transmission and error reporting, and JournalBuilder creates audit trail entries. A new Progressbar wrapper provides import feedback, addressing previous performance issues with parallel imports by ensuring the progress bar is only updated in the parent process. The Routine class orchestrates these components, supporting options like update\_fields, context passing, and failover logic.

lib/chewy/index/import · high confidence

Refactored parameter storage implementation with new type-specific concerns

The parameter storage system in \lib/chewy/search/parameters/concerns\ has been refactored to use distinct modules for different data types, replacing previous inheritance-based approaches. New storage concerns include \BoolStorage\ (which performs value disjunction on updates), \HashStorage\ (which merges hashes with stringified keys), \IntegerStorage\ and \StringStorage\ (which coerce values to their respective types), and \StringArrayStorage\ (which unions arrays). Additionally, \QueryStorage\ has been introduced to handle \query\, \filter\, and \post\_filter\ parameters using Elasticsearch's \bool\ query structure, supporting advanced operations like \must\, \should\, \must\_not\, \and\, \or\, and \minimum\_should\_match\. This change alters how search parameters are merged and updated, particularly for boolean and query-based filters.

lib/chewy/search/parameters/concerns · high confidence

Removal of legacy query criteria and Kaminari-based loading modules

The \Chewy::Query::Criteria\ class, which managed internal storage for search parameters like filters, facets, and sort, has been removed. Additionally, the \Chewy::Query::Loading\ module, which previously handled object loading by wrapping results in Kaminari's \PaginatableArray\, has been deleted. These changes indicate a shift away from the previous internal query structure and the Kaminari dependency for pagination within the query execution layer.

lib/chewy/query · high confidence

Test coverage

Added ActiveRecord test support and refactored class stubbing helpers; Added comprehensive test coverage for Chewy index internals; Added test coverage for Chewy index actions; Added test coverage for Chewy indexing strategies; Added test coverage for Delayed Sidekiq strategy components; Added test coverage for Kaminari pagination integration; Added test coverage for Minitest integration helpers; Added test coverage for search parameter storage classes; Added test coverage for the import subsystem components; Added test coverage for the new Chewy search DSL components; Added tests for Chewy index observation and callback execution; Expanded RSpec matchers for index updates and query building; Expanded test coverage for Chewy core components; Expanded test coverage for Chewy field composition and root index behavior; Modernized test suite and added specs for client lifecycle and index management; Removed legacy Chewy query spec files; Removed legacy Chewy::Type module specs.

Dependencies

Add support for Rails 7.2, 8.0, and 8.1

The gemfiles now include dedicated configurations for Rails 7.2, 8.0, and 8.1, enabling the library to be tested and used with these newer versions of the Rails framework. Each configuration pulls in the corresponding ActiveJob, ActiveRecord, and ActiveSupport gems while reusing a shared base gemfile for common dependencies.

gemfiles · high confidence

Upgrade to Elasticsearch 8 and Ruby 3.2+ requirements

This release updates the core dependency on the Elasticsearch client to version 8 (specifically \>= 8.14, \< 9.0) and raises the minimum required Ruby version to 3.2. The gemspec has been cleaned up with accurate metadata, and the main Gemfile now explicitly includes ActiveRecord, ActiveJob, and Ruby Progressbar while delegating test dependencies to a base gemfile.

(dependencies) · high confidence

Written by watchdog.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.

How this codebase got here

Baseline

  • First survey — no prior run to compare against. CAI 69.

Lenses

  • Code Health 99
  • Architecture 95
  • Maturity 56
  • Readiness 72
  • Security 87

Changes since last survey

  • 300 commits — 244 feature/other, 56 fixes

By area

  • (root) — 136 commits
  • lib/chewy — 63 commits
  • (repo) — 33 commits
  • .github/workflows — 19 commits
  • spec/chewy — 18 commits
  • gemfiles/base.gemfile — 13 commits
  • .circleci/config.yml — 5 commits
  • .github/CODEOWNERS — 5 commits
  • .github/dependabot.yml — 2 commits
  • .github/ISSUE_TEMPLATE — 1 commit
  • .github/PULL_REQUEST_TEMPLATE.md — 1 commit
  • docs/README.md — 1 commit
  • docs/indexing.md — 1 commit
  • lib/chewy.rb — 1 commit
  • spec/support — 1 commit

Notable commits

  • fix: Activate and fix rubocop-rake plugin cops (#1015)
  • fix: Context parallel fix (#1020)
  • fix: Fix CHANGELOG
  • fix: Fix Chewy::Search::Request#only and Chewy::Search::Request#except docs example (#839)
  • fix: Fix FrozenError in Syncer when mutating frozen arrays
  • fix: Fix README.md summary link to ActiveSupport
  • fix: Fix chewy:journal:clean task for ruby 3.x (#874)
  • fix: Fix all ruby 2.7 deprecation warnings
  • fix: Fix clear scroll: pass scroll_id in body, as passing in path parameters is deprecated and can overflow http.max_initial_line_length (#796)
  • fix: Fix deprecation warning for contructing new BigDecimal
  • fix: Fix github CI
  • fix: Fix id conversion issue in delayed_sidekiq strategy (#964)
  • fix: Fix in mock_elasticsearch_response_sources (#861)
  • fix: Fix incorrectly paginated journaling (#848)
  • fix: Fix intermittent time-based failure in delayed sidekiq spec (#947)
  • fix: Fix keyword arguments handling in names scopes (#836)
  • fix: Fix mapping.rb link in Readme (#821)
  • fix: Fix memory leak for ruby 3.2 (#882)
  • fix: Fix misspelled extract_lambdas in Witchcraft (#1030)
  • fix: Fix more ruby 2.7 keyword params deprecation warnings
  • …and 280 more

Written by watchdog.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.

Survey your own repository

toptal/chewy was measured the same way every project in this corpus was: the same rubric, at a pinned commit, with the result published in full. Point a surveyor at a repository you know and see whether you agree with it.

About this page

  • The score is its most recent published measurement, taken on 19 September 2026 at a pinned commit. It is not a live figure and does not change until the project is measured again.
  • Measured at commit 4e7d7025286350135a1b6b8960f3681540ad1ee0 — the exact code this score is about.
  • Scored under rubric-2026.09.15 — the same rubric and the same method as every other entry in this index.
  • Measured by watchdog.canine.dev using codehealth-analyzer preprod-13a154b7f5d1.