{"record":{"id":"6fdea30d0dfc93a9","repo":"elastic/elasticsearch","slug":"bitmap-terms-unknown-token-after","errorCode":null,"errorMessage":"[bitmap_terms] unknown token [{}] after [{}]","messagePattern":"\\[bitmap_terms\\] unknown token \\[(.+?)\\] after \\[(.+?)\\]","errorType":"validation","errorClass":"ParsingException","httpStatus":400,"severity":"error","filePath":"modules/bitmap/src/main/java/org/elasticsearch/index/query/bitmapterms/BitmapTermsQueryBuilder.java","lineNumber":129,"sourceCode":"            if (token == XContentParser.Token.FIELD_NAME) {\n                currentFieldName = parser.currentName();\n            } else if (token.isValue()) {\n                if (\"field\".equals(currentFieldName)) {\n                    fieldName = parser.text();\n                } else if (\"value\".equals(currentFieldName)) {\n                    value = parser.text();\n                } else if (BOOST_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {\n                    boost = parser.floatValue();\n                } else if (NAME_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {\n                    queryName = parser.text();\n                } else {\n                    throw new ParsingException(\n                        parser.getTokenLocation(),\n                        \"[\" + NAME + \"] query does not support [\" + currentFieldName + \"]\"\n                    );\n                }\n            } else {\n                throw new ParsingException(\n                    parser.getTokenLocation(),\n                    \"[\" + NAME + \"] unknown token [\" + token + \"] after [\" + currentFieldName + \"]\"\n                );\n            }\n        }\n        if (fieldName == null) {\n            throw new ParsingException(parser.getTokenLocation(), \"[\" + NAME + \"] requires a [field]\");\n        }\n        if (value == null) {\n            throw new ParsingException(parser.getTokenLocation(), \"[\" + NAME + \"] requires a [value]\");\n        }\n        return new BitmapTermsQueryBuilder(fieldName, value).boost(boost).queryName(queryName);\n    }\n\n    @Override\n    public String getWriteableName() {\n        return NAME;\n    }","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/modules/bitmap/src/main/java/org/elasticsearch/index/query/bitmapterms/BitmapTermsQueryBuilder.java#L111-L147","documentation":"Thrown by BitmapTermsQueryBuilder.fromXContent when the parser encounters a structural token that is neither FIELD_NAME nor a scalar value (e.g. START_OBJECT, START_ARRAY, END_OBJECT in the wrong place). bitmap_terms expects every key to map to a single scalar value; nested objects or arrays are not allowed.","triggerScenarios":"Supplying an array or object where a scalar is expected, e.g. `{\"bitmap_terms\":{\"field\":[\"a\",\"b\"],\"value\":\"...\"}}` or an extra brace producing an unexpected END_OBJECT. Any token where token.isValue() is false and it is not FIELD_NAME triggers it.","commonSituations":"Treating bitmap_terms like a multi-value terms query and passing arrays; malformed JSON from client serializers that wrap scalars in objects; hand-editing JSON and leaving a dangling brace.","solutions":["Ensure field and value are single scalar strings, not arrays or objects.","Validate the JSON is a flat object of scalar key/value pairs with a JSON linter before sending.","Regenerate the body from a known-good BitmapTermsQueryBuilder via doXContent rather than hand-writing."],"exampleFix":"// before\n{\"bitmap_terms\":{\"field\":{\"name\":\"uid\"},\"value\":\"PGJpdG1hcD4=\"}}\n// after\n{\"bitmap_terms\":{\"field\":\"uid\",\"value\":\"PGJpdG1hcD4=\"}}","handlingStrategy":"validation","validationCode":"// Ensure all values are scalars, not arrays/objects.\nfunction assertScalarBody(body) {\n  for (const [k, v] of Object.entries(body)) {\n    if (v !== null && typeof v === \"object\") {\n      throw new Error(`bitmap_terms [${k}] must be a scalar, got ${Array.isArray(v) ? \"array\" : \"object\"}`);\n    }\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass the body through a JSON validator that rejects nested structures for bitmap_terms.","Build the body with the Java/REST client builder API which only emits scalars."],"tags":["bitmap-terms","query-dsl","parsing","elasticsearch"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}