{"record":{"id":"6af28d8988b2346c","repo":"dgraph-io/dgraph","slug":"facets-format-should-be-of-type-map-for-scalarlist","errorCode":null,"errorMessage":"facets format should be of type map for scalarlist predicates, found: %v for facet: %v","messagePattern":"facets format should be of type map for scalarlist predicates, found: (.+?) for facet: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"chunker/json_parser.go","lineNumber":133,"sourceCode":"// Map key would be the index of scalar value for respective facets.\nfunc parseMapFacets(m map[string]interface{}, prefix string) ([]map[int]*api.Facet, error) {\n\t// This happens at root.\n\tif prefix == \"\" {\n\t\treturn nil, nil\n\t}\n\n\tvar mapSlice []map[int]*api.Facet\n\tfor fname, facetVal := range m {\n\t\tif facetVal == nil {\n\t\t\tcontinue\n\t\t}\n\t\tif !strings.HasPrefix(fname, prefix) {\n\t\t\tcontinue\n\t\t}\n\n\t\tfm, ok := facetVal.(map[string]interface{})\n\t\tif !ok {\n\t\t\treturn nil, fmt.Errorf(\"facets format should be of type map for \"+\n\t\t\t\t\"scalarlist predicates, found: %v for facet: %v\", facetVal, fname)\n\t\t}\n\n\t\tidxMap := make(map[int]*api.Facet, len(fm))\n\t\tfor sidx, val := range fm {\n\t\t\tkey := fname[len(prefix):]\n\t\t\tfacet, err := handleBasicFacetsType(key, val)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"facet: %s, index: %s: %w\", fname, sidx, err)\n\t\t\t}\n\t\t\tidx, err := strconv.Atoi(sidx)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"facet: %s, index: %s: %w\", fname, sidx, err)\n\t\t\t}\n\t\t\tidxMap[idx] = facet\n\t\t}\n\t\tmapSlice = append(mapSlice, idxMap)\n\t}","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/chunker/json_parser.go#L115-L151","documentation":"The hash tokenizer computes a BLAKE2b-256 digest of a string value. Because hashing is only defined for string inputs here, Tokens() type-asserts v.(string) and returns this error for any other dynamic type.","triggerScenarios":"Calling HashTokenizer.Tokens(v) with a non-string value — e.g. tokenizing an int64 uid value or bool through the hash index path.","commonSituations":"Schema uses @index(hash) on a non-string predicate; code passes []byte or typed values without converting to string before tokenization.","solutions":["Make the predicate a string type in the schema if hash indexing is desired.","Convert the value with fmt.Sprintf or strconv before calling Tokens.","Remove @index(hash) from non-string predicates."],"exampleFix":"// before\ntok.HashTokenizer{}.Tokens(12345) // error\n// after\ntok.HashTokenizer{}.Tokens(strconv.FormatInt(12345, 10))","handlingStrategy":"type-guard","validationCode":"if s, ok := v.(string); !ok {\n    return fmt.Errorf(\"hash tokenizer requires string, got %T\", v)\n}","typeGuard":"func isHashableString(v interface{}) bool { _, ok := v.(string); return ok }","tryCatchPattern":"tokens, err := hashTok.Tokens(v)\nif err != nil && strings.Contains(err.Error(), \"Hash tokenizer only supported for string\") {\n    s := fmt.Sprintf(\"%v\", v)\n    tokens, err = hashTok.Tokens(s)\n}","preventionTips":["Only use @index(hash) on string predicates.","Stringify values (strconv/fmt) before tokenizing non-string scalars.","Centralize tokenization behind a helper that enforces the string type."],"tags":["dgraph","tokenizer","hash","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"}