Repository navigation
fix(elasticsearch): read activity logs and trackers by the complete object ID - #61
Merged
paullla merged 2 commits intoDec 4, 2026
Merged
Conversation
…bject ID The default index mapping saves objectId as analyzed text, and the storage read it with a term query. Such a query compares words and not the complete ID. A read for the ID "15" also returned the logs of the ID "15-b", and a read for "15-b" or a UUID returned nothing. The read of the current data tracker used the same query, so the bundle did not log updates of such objects. ElasticsearchExactMatchQuery builds a search body with two checks: a phrase query on the indexed field, which keeps the read fast, and a term query on a runtime keyword field that reads the saved value from the document source, which makes the read exact. Existing indexes work, and a reindex is not necessary. ElasticsearchActivityLogStorage::findByIndexAndObjectId() and ElasticsearchCurrentDataTrackerStorage::findByClassAndObjectId() use the new class. A server that does not permit runtime fields or inline scripts gets the phrase query alone, so the reads do not fail there.
…service The two storages wrapped their service call in a callback of ElasticsearchExactMatchQuery, which ran the search again when a server did not permit the exact check. The storages now build the search body and make the plain getItemByQuery() and getCollection() calls again. ElasticsearchService runs the search. If the server rejects the exact checks of the search body, it runs the search one more time with no exact checks. Other errors, and a rejected search body that is not from the bundle, go to the caller. ElasticsearchExactMatchQuery only builds and changes search bodies. Its search() method with the @template type is removed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
With
storage: elasticsearch, the default index mapping savesobjectIdas analyzed text, and the storage read it with atermquery. Such a query compares words and not the complete ID:getActivityLogsByClassAndId()with the ID15also returned the logs of the ID15-b.15-bor a UUID, it returned nothing.15when15-balso exists. The update handler then saved no log, so the bundle did not log updates of such objects.Number IDs with no similar ID worked. The
doctrineandin_memorystorages did not have this defect.Changes
Bridge\Elasticsearch\Query\ElasticsearchExactMatchQuery. Its search body has two checks: a phrase query on the indexed field, which keeps the read fast, and a term query on a runtime keyword field that reads the saved value from the document source, which makes the read exact. Existing indexes work, and a reindex is not necessary.ElasticsearchActivityLogStorage::findByIndexAndObjectId()andElasticsearchCurrentDataTrackerStorage::findByClassAndObjectId()use the new class.search.allow_expensive_queries: false,script.allowed_types,script.allowed_contexts) gets the phrase query alone, so the reads do not fail there.ElasticsearchServicedoes this second search forgetItemByQuery()andgetCollection().Backward compatibility
Editedlog of an object that had the defect shows all changes since its last saved tracker. The CHANGELOG says how to start from the current data instead.Verification
master), and 39 unit tests of the new class, the service and the two storages. Full suite: 168 tests pass. PHPStan reports no errors, and PHP-CS-Fixer reports 0 fixable files.objectIdaskeyword,objectIdaslong, and an index with no mapping.