Skip to content

fix(elasticsearch): refresh the index on bulkCreate like single-item writes - #42

Merged
paullla merged 2 commits into
Locastic:masterfrom
paullla:fix/bulk-create-refresh
Jul 3, 2026
Merged

fix(elasticsearch): refresh the index on bulkCreate like single-item writes#42
paullla merged 2 commits into
Locastic:masterfrom
paullla:fix/bulk-create-refresh

Conversation

@paullla

@paullla paullla commented Jul 3, 2026

Copy link
Copy Markdown
Member
Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Issues -
License MIT

Problem

ElasticsearchService::createItem() and updateItem() request refresh=true, so written documents are immediately searchable, and the update flow relies on that (create -> immediate update reads the tracker back). bulkCreate() does not refresh, so current data trackers written by locastic:activity-logs:populate-current-data-trackers are invisible to the tracker lookup until Elasticsearch refreshes on its own (default 1s). Update logs arriving in that window are silently dropped: the handler finds no tracker and returns early, meaning the very first change after repopulating trackers can go unlogged.

Found running a backend-parity harness against a demo app: a populate-then-update sequence logged the change on a relational storage adapter but dropped it on Elasticsearch.

Changes

  • bulkCreate() sends refresh: 'true', consistent with the other write methods. Populate runs in batches of 250 per message, so one refresh per batch is a negligible cost for an occasional admin operation

Verification

  • The parity harness (create trackers via populate, update the entity immediately, expect an Edited log with the correct diff) fails on Elasticsearch 9.0 before this change and passes after; the same harness passes on the relational adapter both times
  • Full PHPUnit suite (24 tests, 53 assertions) green against Elasticsearch 9.0; PHP-CS-Fixer clean

paullla added 2 commits July 3, 2026 14:02
…writes

createItem() and updateItem() request refresh=true so written documents
are immediately searchable, but bulkCreate() did not. Current data
trackers written by the populate command were therefore invisible to
the tracker lookup until Elasticsearch refreshed on its own, and update
logs arriving in that window were silently dropped because the handler
found no tracker to compare against.
@paullla
paullla merged commit ea7cbcb into Locastic:master Jul 3, 2026
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant