{"record":{"id":"7cc44272fc1e3843","repo":"dgraph-io/dgraph","slug":"facet-value-can-only-be-string-number-bool","errorCode":null,"errorMessage":"facet value can only be string/number/bool","messagePattern":"facet value can only be string/number/bool","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"chunker/json_parser.go","lineNumber":90,"sourceCode":"\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\tjsonValue = jsonInt\n\t\t\tvalueType = api.Facet_INT\n\t\t}\n\t// these int64/float64 cases are needed for the FastParseJSON simdjson\n\t// parser, which doesn't use json.Number\n\tcase int64:\n\t\tjsonValue = v\n\t\tvalueType = api.Facet_INT\n\tcase float64:\n\t\tjsonValue = v\n\t\tvalueType = api.Facet_FLOAT\n\tcase bool:\n\t\tjsonValue = v\n\t\tvalueType = api.Facet_BOOL\n\tdefault:\n\t\treturn nil, errors.New(\"facet value can only be string/number/bool\")\n\t}\n\n\t// Convert facet val interface{} to binary.\n\tbinaryValueFacet, err := facets.ToBinary(key, jsonValue, valueType)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn binaryValueFacet, nil\n}\n\n// parseMapFacets parses facets which are of map type. Facets for scalar list predicates are\n// specified in map format. For example below predicate nickname and kind facet associated with it.\n// Here nickname \"bob\" doesn't have any facet associated with it.\n//\n//\t{\n//\t\t\"nickname\": [\"alice\", \"bob\", \"josh\"],\n//\t\t\"nickname|kind\": {","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/chunker/json_parser.go#L72-L108","documentation":"The trigram tokenizer splits a string into all 3-character substrings for trigram indexing. Tokens() asserts the input is a string; any other dynamic type returns this error since trigram indexing is defined only for strings.","triggerScenarios":"Calling TrigramTokenizer.Tokens(v) with a non-string value (int, float, bool, time.Time, []byte, etc.).","commonSituations":"Schema has @index(trigram) on a non-string predicate (e.g. a datetime or int); generic indexing code passes interface{} values straight to the tokenizer without a string check.","solutions":["Ensure the predicate indexed with trigram is of type string in the schema.","Remove @index(trigram) from non-string predicates or switch to a suitable index.","Cast/convert the value to string at the call site when intentional."],"exampleFix":"// before\npred: \"released\" @index(trigram) . // datetime\n// after\npred: \"title\" @index(trigram) . // string","handlingStrategy":"type-guard","validationCode":"if s, ok := v.(string); !ok {\n    return fmt.Errorf(\"trigram tokenizer requires string, got %T\", v)\n}","typeGuard":"func asString(v interface{}) (string, bool) { s, ok := v.(string); return s, ok }","tryCatchPattern":"tokens, err := trigramTok.Tokens(v)\nif err != nil && strings.Contains(err.Error(), \"Trigram indices only supported for string\") {\n    return nil, fmt.Errorf(\"trigram index requires a string predicate; got %T\", v)\n}","preventionTips":["Restrict @index(trigram) to string predicates in schema review.","Convert []byte/datetime values to string explicitly before tokenizing.","Add unit tests asserting tokenizer input types match schema types."],"tags":["dgraph","tokenizer","trigram","type-mismatch"],"backgroundTag":"tokenizer-type-mismatch","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}