{"id":"887b849d275104e1","repo":"gohugoio/hugo","slug":"index-q-not-found","errorCode":null,"errorMessage":"index %q not found","messagePattern":"index %q not found","errorType":"exception","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/8a468df065a75c1c7cf9f6850f32148746590ea5/related/inverted_index.go#L341-L377","documentation":"`InvertedIndex.Search` (related/inverted_index.go:346) restricts a related-content query to the index names given in SearchOpts.Indices or in named argument slices. Each name is looked up against the configured `related.indices` (config lookup at getIndexCfg); an unknown name means the query references an index that was never configured, so Hugo fails instead of silently returning no matches.","triggerScenarios":"Calling `.Related` / `site.RegularPages.Related` with an `indices` option or a named argument (e.g. `keyvals \"series\" ...`) whose name doesn't match any entry in the site's `related.indices` config (inverted_index.go:357-359 and 395-398).","commonSituations":"Template uses `related.indices` names that were removed or renamed in config; relying on Hugo's default related config (keywords, date) while querying a custom index like `tags` that was never added; case/typo mismatches (index names are lower-cased in config decoding).","solutions":["Add the missing index to `related.indices` in your site config (e.g. `[[related.indices]] name = 'tags' weight = 80`).","Fix the index name in the template call to match a configured index (names are lower-case).","If you customized `related`, remember it replaces the defaults entirely — re-declare any default indices you still query."],"exampleFix":"// before (layouts template)\n{{ $related := site.RegularPages.Related (dict \"document\" . \"indices\" (slice \"tags\")) }}\n# after (hugo.toml)\n[related]\n  [[related.indices]]\n    name = \"tags\"\n    weight = 80","handlingStrategy":"validation","validationCode":"# Declare every index you query in site config before using .Related\n[related]\n  [[related.indices]]\n    name = \"keywords\"\n    weight = 100","typeGuard":"func hasIndex(cfg related.Config, name string) bool {\n    for _, ic := range cfg.Indices {\n        if strings.EqualFold(ic.Name, name) { return true }\n    }\n    return false\n}","tryCatchPattern":"related, err := idx.Search(cfg)\nif err != nil {\n    return fmt.Errorf(\"related search failed — is the index declared in [related.indices]?: %w\", err)\n}","preventionTips":["Only pass index names to related-content searches that appear under `related.indices` in site config","Remember Hugo's defaults are `keywords` and `date` — any other name must be configured explicitly","Keep template `.RelatedIndices` arguments in sync when renaming indices in config"],"tags":["related-content","config","templates"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}