Fix filtering events by layer on the Elasticsearch storage - #14087
Merged
Merged
Conversation
wu-sheng
approved these changes
Sep 17, 2026
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.
Fix filtering events by layer on the Elasticsearch storage
Why the bug exists
An event's
layeris written and read as a number, but the Elasticsearch query filters it with the layername:
Event.Builder#entity2Storage:converter.accept(LAYER, layer != null ? layer.value() : Layer.UNDEFINED.value()), andLayer.GENERALis2;Event.Builder#storage2Entity(Layer.valueOf(((Number) …).intValue())) andESEventQueryDAO#parseSearchHit(Layer.valueOf(Integer.parseInt(…)));ESEventQueryDAO#buildMustQueryListByConditionsends the raw string:query.must(Query.term(Event.LAYER, condition.getLayer())).EventQueryCondition#layeris aString(seeevent.graphqls), and a client always fills it with theupper-snake layer name — Horizon UI's events feed does
layer: body.layer.toUpperCase(). Elasticsearch istherefore asked for
{"term":{"layer":"GENERAL"}}against a numeric field and fails while building thequery, so the whole request returns 400
number_format_exception: For input string: "GENERAL", on an emptyindex just as well. In Horizon UI this makes the per-service events popout fail for every service.
How it is fixed
Convert the name to the value before building the term — which is what the other two storages already do:
JDBCEventQueryDAO#buildQuery:parameters.add(String.valueOf(Layer.nameOf(condition.getLayer()).value()));BanyanDBEventQueryDAO#doQuery:group.eq(Event.LAYER, Layer.valueOf(condition.getLayer()).value());This PR only aligns the Elasticsearch plugin with them:
Layer.nameOfmatches the JDBC storage, which maps an unknown name toUNDEFINEDinstead of throwing.I am happy to use the stricter
Layer.valueOfto match BanyanDB instead, if that is preferred — it is aone-word change. (
Layeris already imported in this file.)How it was verified
The new
ESEventQueryDAOTestbuilds the search body forlayer = "GENERAL"and asserts it carries"layer":2and no longer contains the layer name. Run againstmaster(fix reverted) it fails andprints the offending body verbatim, which is the whole bug in one line:
{"from":0,"size":10,"query":{"bool":{"must":[{"term":{"layer":"GENERAL"}}]}},"sort":[{"timestamp":{"order":"desc"}}],"aggregations":null,"_source":null}With the fix applied the same test passes (
Tests run: 1, Failures: 0, Errors: 0).maven-checkstyle-plugin:3.1.0:checkruns on this module as usual (includeTestSourceDirectory=true,so the new test is covered too) — BUILD SUCCESS.
Against a live Elasticsearch storage, an event query carrying a layer name returns 400
number_format_exception: For input string: "GENERAL", while the same query with the layer valuereturns the events of that layer. That 400 is what Horizon UI receives from its events popout.
layerfilter always fails on Elasticsearch storage: number_format_exception For input string: "GENERAL" #14086.CHANGESlog.