{"record":{"id":"3c2b7d8caad1b8a8","repo":"quarkusio/quarkus","slug":"cannot-use-on-hash-and-on-json-at-the-same-tim","errorCode":null,"errorMessage":"Cannot use `ON HASH` and `ON JSON` at the same time","messagePattern":"Cannot use `ON HASH` and `ON JSON` at the same time","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/search/CreateArgs.java","lineNumber":297,"sourceCode":"    /**\n     * Adds a field to the schema.\n     *\n     * @param field the field\n     * @param alias the alias, can be {@code null}\n     * @param type the field type\n     * @return the current {@code CreateArgs}\n     */\n    public CreateArgs indexedField(String field, String alias, FieldType type) {\n        return indexedField(field, alias, type, null);\n    }\n\n    @Override\n    public List<Object> toArgs() {\n        List<Object> list = new ArrayList<>();\n\n        if (onHash) {\n            if (onJson) {\n                throw new IllegalArgumentException(\"Cannot use `ON HASH` and `ON JSON` at the same time\");\n            }\n            list.add(\"ON\");\n            list.add(\"HASH\");\n        }\n\n        if (onJson) {\n            list.add(\"ON\");\n            list.add(\"JSON\");\n        }\n\n        if (prefixes != null && prefixes.length > 0) {\n            list.add(\"PREFIX\");\n            list.add(Integer.toString(prefixes.length));\n            list.addAll(Arrays.asList(prefixes));\n        }\n\n        if (filter != null) {\n            list.add(\"FILTER\");","sourceCodeStart":279,"sourceCodeEnd":315,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/search/CreateArgs.java#L279-L315","documentation":"RediSearch FT.CREATE allows only one ON <type> clause selecting the data structure to index. CreateArgs.toArgs() throws IllegalArgumentException when both onHash and onJson were requested, because the generated ON HASH ON JSON command would be invalid.","triggerScenarios":"Calling ft().create(index, new CreateArgs().onHash().onJson(), schema) — i.e. chaining both onHash() and onJson() on the same CreateArgs instance, typically from conditional building code that sets both flags from user/config input.","commonSituations":"Trying to index both hash and JSON documents with a single index; conditional builder code where two branches both fire instead of being exclusive; migrating code where the storage type switched but the old onHash() call was left in place.","solutions":["Call exactly one of onHash() or onJson() on the CreateArgs","Create two separate indexes if both hash and JSON documents must be indexed","Check conditional building logic so only one branch sets the ON type"],"exampleFix":"// before\nCreateArgs args = new CreateArgs().onHash();\nif (useJson) args.onJson(); // throws when useJson is true\n// after\nCreateArgs args = useJson ? new CreateArgs().onJson() : new CreateArgs().onHash();","handlingStrategy":"validation","validationCode":"if (indexHash && indexJson) throw new IllegalStateException(\"Create one index per document type; ON HASH and ON JSON cannot be combined\");\nCreateArgs args = indexJson ? new CreateArgs().onJson() : new CreateArgs().onHash();","typeGuard":"boolean validOnType(CreateArgs args, boolean onHash, boolean onJson) {\n    return !(onHash && onJson);\n}","tryCatchPattern":"try {\n    ft.create(index, args, schema);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"ON HASH\")) {\n        throw new IllegalStateException(\"Index must target exactly one document type\", e);\n    }\n    throw e;\n}","preventionTips":["Pick exactly one ON type per FT.CREATE index","Create separate indexes for hash and JSON documents","Guard conditional builder logic with if/else, not consecutive ifs"],"tags":["redis","redisearch","illegal-argument","client-side-validation","mutually-exclusive-args"],"backgroundTag":"mutually-exclusive-options","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}