{"record":{"id":"82cd9522d6d5f641","repo":"elastic/elasticsearch","slug":"bitmap-terms-field-name-cannot-be-null-or-empty","errorCode":null,"errorMessage":"[bitmap_terms] field name cannot be null or empty","messagePattern":"\\[bitmap_terms\\] field name cannot be null or empty","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":400,"severity":"error","filePath":"modules/bitmap/src/main/java/org/elasticsearch/index/query/bitmapterms/BitmapTermsQueryBuilder.java","lineNumber":64,"sourceCode":" *   \"bitmap_terms\": {\n *     \"field\": \"my_long_field\",\n *     \"value\": \"<base64-encoded bitmap>\"\n *   }\n * }\n * }</pre>\n */\npublic class BitmapTermsQueryBuilder extends LeafQueryBuilder<BitmapTermsQueryBuilder> {\n\n    public static final String NAME = \"bitmap_terms\";\n\n    static final TransportVersion BITMAP_TERMS_QUERY_ADDED = TransportVersion.fromName(\"bitmap_terms_query_added\");\n\n    private final String fieldName;\n    private final String value;\n\n    public BitmapTermsQueryBuilder(String fieldName, String value) {\n        if (fieldName == null || fieldName.isBlank()) {\n            throw new IllegalArgumentException(\"[bitmap_terms] field name cannot be null or empty\");\n        }\n        if (value == null) {\n            throw new IllegalArgumentException(\"[bitmap_terms] value cannot be null\");\n        }\n        this.fieldName = fieldName;\n        this.value = value;\n    }\n\n    public BitmapTermsQueryBuilder(StreamInput in) throws IOException {\n        super(in);\n        this.fieldName = in.readString();\n        this.value = in.readString();\n    }\n\n    @Override\n    protected void doWriteTo(StreamOutput out) throws IOException {\n        out.writeString(fieldName);\n        out.writeString(value);","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/modules/bitmap/src/main/java/org/elasticsearch/index/query/bitmapterms/BitmapTermsQueryBuilder.java#L46-L82","documentation":"BitmapTermsQueryBuilder constructor validates fieldName up-front: null or isBlank() (empty or whitespace-only) throws IllegalArgumentException. This is the leaf query used by the bitmap_terms query type. The check is a pure precondition before any field is resolved against a mapping.","triggerScenarios":"Constructing a BitmapTermsQueryBuilder via the Java API or the REST query DSL with a missing, null, or whitespace field name — e.g. sending {\"bitmap_terms\": {\"value\": \"x\"}} with no 'field', or an explicit null field.","commonSituations":"Programmatic query building where the field name comes from user input that was not validated; JSON deserialisation edge case where the field key was omitted; templated query that left field blank.","solutions":["Always supply a non-blank field name when constructing the query.","Validate fieldName at the application boundary before passing it to the builder.","For REST requests, ensure the 'field' key is present and non-empty in the bitmap_terms body."],"exampleFix":"// before\nnew BitmapTermsQueryBuilder(null, value)\nnew BitmapTermsQueryBuilder(\"  \", value)\n// after\nnew BitmapTermsQueryBuilder(\"category_id\", value)","handlingStrategy":"type-guard","validationCode":"static String requireFieldName(String f) {\n  if (f == null || f.isBlank()) throw new IllegalArgumentException(\"field required\");\n  return f;\n}","typeGuard":"// Narrow a String to a non-blank field name before constructing the query\nstatic boolean isUsableFieldName(String f) {\n  return f != null && !f.isBlank();\n}","tryCatchPattern":null,"preventionTips":["Validate field names at the application boundary before building queries.","For REST requests, schema-check the bitmap_terms body for a non-empty 'field'."],"tags":["bitmap","query","validation","constructor"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}