You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 2b9463c
Browse filesBrowse the repository at this point in the historyBrowse files
Add customize_config API for customizing index datastore configuration (#1366)
Implements the `i.customize_config` proposal from #1364
(#1364 (comment)).
## Schema definition API
```ruby
schema.object_type "Campaign" do |t|
# ...
t.index "campaigns" do |i|
i.rollover :monthly, "createdAt"
i.customize_config do |config|
# Index aliases
config["aliases"] = {
"campaigns_read" => {},
"campaigns_active" => {"filter" => {"term" => {"status" => "ACTIVE"}}}
}
# Field alias: lets direct datastore queries reference `created` as an alias of `createdAt`
config["mappings"]["properties"]["created"] = {"type" => "alias", "path" => "createdAt"}
end
end
end
```
Semantics match the proposal:
- The block mutates the yielded config hash; the return value is
ignored. ElasticGraph yields a defensive deep copy so mutations can't
corrupt its internal structures (parts of `mappings` are shared across
indices).
- The yielded hash is "the config every concrete index for this index
definition gets" — the template body for rollover index defs, the index
config otherwise.
- The result is baked into `datastore_config.yaml`, so it's diffable in
PRs and `elasticgraph-admin` treats it identically to built-in config.
- Multiple `customize_config` blocks compose in registration order.
- Nested customizations — like the field alias above — work for both
indices and index templates, since the block mutates the full config in
place. On the admin side they ride the existing mappings reconciliation:
included at index/template creation, added to already-existing indices
(including pre-existing rollover indices) via the mapping update path,
and idempotent on reconvergence.
- The YARD docs carry the "ElasticGraph passes this through and makes no
claims about safety/correctness — use with care!" caveat.
## Admin changes so customizations are fully respected
The three changes outlined in the proposal:
1. **Absent means "leave alone".** On template updates, desired aliases
are merged over the template's current ones instead of replacing them —
the same policy admin already applies to no-longer-desired mapping
fields. This fixes the out-of-band alias clobbering regardless of
whether anyone uses the new API.
2. **Template update trigger.** `ForIndexTemplate#configure!` now diffs
the full desired vs. current template body (not just mappings/settings),
so a customization-only change still reaches the datastore. To keep this
comparison stable, `IndexConfigNormalizer` now treats an empty `aliases`
hash the same as an absent one (the datastore doesn't consistently echo
the key back).
3. **Reconciliation of existing concrete indices.**
`ForIndex#configure!` gained an `_aliases` step (after mappings, since
alias filters can reference newly-added fields): it adds/updates desired
aliases and never removes undeclared ones. A newly declared alias now
lands on pre-existing rollover indices rather than only on ones created
afterward.
Both datastore clients gained an `update_index_aliases` method (plus
dry-run decorator no-op, RBS interface entry, and parallel-spec-runner
support).
## Testing
- Unit specs for the schema definition API (application to index config
vs. template body, block composition, defensive copy, nested
customizations, no-block error).
- Shared admin integration specs (run for both `ForIndex` and
`ForIndexTemplate`): create-with-aliases + idempotent reconvergence,
adding/updating aliases on existing indices and templates, and leaving
undeclared (out-of-band) aliases alone. A template-specific spec
verifies aliases are stamped onto concrete rollover indices at creation
and reconciled onto pre-existing ones.
- A shared integration spec covers field aliases end-to-end for both
configurators: declared via `customize_config`, applied at creation,
reconciled onto an already-existing index/template via the mapping
update path, and idempotent on re-run.
- `datastore_config.yaml` emission is unchanged for schemas that don't
use the new API (repo artifacts show no diff after
`schema_artifacts:dump`).
- Full suite green (5315 examples, 0 failures), `script/type_check`
clean, 100% doc coverage maintained, `site:doctest` passes.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Myron Marston <myron.marston@gmail.com>
0 commit comments