{"record":{"id":"1148b2b321973fa0","repo":"elastic/elasticsearch","slug":"bitmap-terms-query-on-long-field-only-supports","errorCode":null,"errorMessage":"[bitmap_terms] query on [long] field only supports non-negative values (0 to 9223372036854775807)","messagePattern":"\\[bitmap_terms\\] query on \\[long\\] field only supports non-negative values \\(0 to 9223372036854775807\\)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":400,"severity":"error","filePath":"modules/bitmap/src/main/java/org/elasticsearch/index/query/bitmapterms/BitmapTermsQueryBuilder.java","lineNumber":207,"sourceCode":"            throw new IllegalArgumentException(\n                \"[bitmap_terms] query on [integer] field only supports non-negative values (0 to 2147483647)\"\n            );\n        }\n        return bitmap;\n    }\n\n    private static LongBitmap longValues(byte[] bitmapBytes) {\n        LongBitmap bitmap;\n        try {\n            bitmap = LongBitmap.deserializePortable(bitmapBytes);\n        } catch (Exception e) {\n            throw new IllegalArgumentException(\n                \"[bitmap_terms] query value is not a valid serialized 64-bit RoaringBitmap in the portable format\",\n                e\n            );\n        }\n        if (bitmap.hasNegativeValues()) {\n            throw new IllegalArgumentException(\n                \"[bitmap_terms] query on [long] field only supports non-negative values (0 to 9223372036854775807)\"\n            );\n        }\n        return bitmap;\n    }\n\n    @Override\n    protected int doHashCode() {\n        return Objects.hash(fieldName, value);\n    }\n\n    @Override\n    protected boolean doEquals(BitmapTermsQueryBuilder other) {\n        return Objects.equals(fieldName, other.fieldName) && Objects.equals(value, other.value);\n    }\n\n    @Override\n    public TransportVersion getMinimalSupportedVersion() {","sourceCodeStart":189,"sourceCodeEnd":225,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/modules/bitmap/src/main/java/org/elasticsearch/index/query/bitmapterms/BitmapTermsQueryBuilder.java#L189-L225","documentation":"Thrown by longValues after a successful 64-bit portable deserialize when the bitmap contains negative values. long fields are signed 64-bit but bitmap_terms restricts to the non-negative range [0, 9223372036854775807].","triggerScenarios":"A 64-bit bitmap holding values whose high bit is set (>= 2^63), which would be negative java longs. Usually a client treating the bitmap as unsigned 64-bit while the field is signed.","commonSituations":"Hashing step that produces unsigned 64-bit values with the high bit set; mixing unsigned conventions between producer and consumer.","solutions":["Ensure all values in the 64-bit bitmap are in [0, 9223372036854775807].","Mask or fold high-bit values on the producer side before serializing.","If the domain genuinely needs the full unsigned range, redesign to split into two signed fields."],"exampleFix":"// before\nbitmap.addLong(0xF000000000000000L) // high bit set, negative as signed long\n// after\nbitmap.addLong(0x7000000000000000L) // within non-negative signed range","handlingStrategy":"validation","validationCode":"// Reject negative/high-bit signed longs before serializing for a long field.\nfor (long v : values) {\n  if (v < 0) {\n    throw new IllegalArgumentException(\"long bitmap value must be non-negative: \" + v);\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Bound-check all values against [0, Long.MAX_VALUE].","Mask or fold hash outputs that can set the high bit."],"tags":["bitmap-terms","roaring-bitmap","integer-overflow","elasticsearch"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}