{"record":{"id":"887b849d275104e1","repo":"gohugoio/hugo","slug":"index-q-not-found","errorCode":null,"errorMessage":"index %q not found","messagePattern":"index %q not found","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"related/inverted_index.go","lineNumber":359,"sourceCode":"// against query options in opts.\n// The resulting document set will be sorted according to number of matches\n// and the index weights, and any matches with a rank below the configured\n// threshold (normalize to 0..100) will be removed.\n// If an index name is provided, only that index will be queried.\nfunc (idx *InvertedIndex) Search(ctx context.Context, opts SearchOpts) ([]Document, error) {\n\tvar (\n\t\tqueryElements []queryElement\n\t\tconfigs       IndicesConfig\n\t)\n\n\tif len(opts.Indices) == 0 {\n\t\tconfigs = idx.cfg.Indices\n\t} else {\n\t\tconfigs = make(IndicesConfig, len(opts.Indices))\n\t\tfor i, indexName := range opts.Indices {\n\t\t\tcfg, found := idx.getIndexCfg(indexName)\n\t\t\tif !found {\n\t\t\t\treturn nil, fmt.Errorf(\"index %q not found\", indexName)\n\t\t\t}\n\t\t\tconfigs[i] = cfg\n\t\t}\n\t}\n\n\tfor _, cfg := range configs {\n\t\tvar keywords []Keyword\n\t\tif opts.Document != nil {\n\t\t\tk, err := opts.Document.RelatedKeywords(cfg)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\tkeywords = append(keywords, k...)\n\t\t}\n\t\tif cfg.Type == TypeFragments {\n\t\t\tfor _, fragment := range opts.Fragments {\n\t\t\t\tkeywords = append(keywords, FragmentKeyword(fragment))\n\t\t\t}","sourceCodeStart":341,"sourceCodeEnd":377,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/related/inverted_index.go#L341-L377","documentation":"Returned by InvertedIndex.Search when one of the index names in opts.Indices does not match any IndexConfig.Name in the configured indices. The search validates each requested index name against the config before building the query, so a typo or a removed index name fails fast here.","triggerScenarios":"Calling Search with SearchOpts{Indices: []string{\"tags\"}} when the related config only defines indices named \"keywords\" and \"date\". Also triggered when related search templates reference an index that was renamed or removed in a config refactor.","commonSituations":"Renaming an index in the [related] config without updating related.html partial that references the old name; configuring a custom index but misspelling it in a template; upgrading Hugo where default index names changed.","solutions":["Check the [related.indices] config in hugo.toml and confirm the index Name matches what is passed to Search.","Update any templates/partials that call .Related / Related indexing to use the current index name.","Remember index names are lowercased during DecodeConfig -- supply lowercase names."],"exampleFix":"// before: config defines \"keywords\" but search asks for \"tags\"\nrelated, _ := idx.Search(ctx, related.SearchOpts{Indices: []string{\"tags\"}})\n\n// after\nrelated, _ := idx.Search(ctx, related.SearchOpts{Indices: []string{\"keywords\"}})","handlingStrategy":"validation","validationCode":"// Verify index names exist before searching.\nfunc validIndexNames(cfg related.Config, names []string) error {\n    known := map[string]bool{}\n    for _, i := range cfg.Indices { known[strings.ToLower(i.Name)] = true }\n    for _, n := range names {\n        if !known[strings.ToLower(n)] {\n            return fmt.Errorf(\"unknown related index %q\", n)\n        }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"docs, err := idx.Search(ctx, related.SearchOpts{Indices: names})\nif err != nil && strings.Contains(err.Error(), \"not found\") {\n    // index name mismatch -- fix config or input\n}","preventionTips":["Keep a single source of truth for index names shared between config and templates.","Lowercase all index names in queries.","After renaming an index, grep templates for the old name."],"tags":["related","search","config","index"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}