gohugoio/hugo · error

index for %q not found

Error message

index for %q not found

What it means

Returned by InvertedIndex.searchDate when the internal index map (idx.index) does not contain an entry for a query element's Index name. This is a lower-level lookup distinct from the config lookup: it checks the actual posting-list map. A mismatch implies the query element references an index that was never allocated during NewInvertedIndex.

Source

Thrown at related/inverted_index.go:474

func (idx *InvertedIndex) search(ctx context.Context, query ...queryElement) ([]Document, error) {
	return idx.searchDate(ctx, nil, zeroDate, query...)
}

func (idx *InvertedIndex) searchDate(ctx context.Context, self Document, upperDate time.Time, query ...queryElement) ([]Document, error) {
	matchm := make(map[Document]*rank, 200)
	defer func() {
		for _, r := range matchm {
			putRank(r)
		}
	}()

	applyDateFilter := !idx.cfg.IncludeNewer && !upperDate.IsZero()
	var fragmentsFilter collections.SortedStringSlice

	for _, el := range query {
		setm, found := idx.index[el.Index]
		if !found {
			return []Document{}, fmt.Errorf("index for %q not found", el.Index)
		}

		config, found := idx.getIndexCfg(el.Index)
		if !found {
			return []Document{}, fmt.Errorf("index config for %q not found", el.Index)
		}

		for _, kw := range el.Keywords {
			if docs, found := setm[kw]; found {
				for _, doc := range docs {
					if compare.Eq(doc, self) {
						continue
					}

					if applyDateFilter {
						// Exclude newer than the limit given
						if doc.PublishDate().After(upperDate) {
							continue

View on GitHub (pinned to 52c9bd7908)

Solutions

  1. Ensure NewInvertedIndex is constructed with the same Config whose index names are used in queries.
  2. Do not construct queryElement directly outside the package; use Search/SearchOpts which validates names.
  3. Recreate the InvertedIndex if the related config changes at runtime.

Example fix

// before: index built with one config, queried with names from another
idx := related.NewInvertedIndex(cfgA)
idx.searchDate(ctx, doc, t, queryElement{Index: "onlyInCfgB"})

// after: rebuild with the active config
idx := related.NewInvertedIndex(activeCfg)
Defensive patterns

Strategy: validation

Validate before calling

// Ensure the index name was registered at construction.
func registeredNames(idx *related.InvertedIndex) []string {
    // idx.index keys are the allocated names; expose them in your wrapper
    return /* names from the Config used to build idx */
}

Prevention

When it happens

Trigger: Reached only if a queryElement reaches searchDate with an Index name absent from idx.index. In normal flow Search validates names first (errors 523/525), so this is a defensive guard for internal callers that construct queryElements directly or a config/index-map inconsistency.

Common situations: Internal code constructing queryElement with an index name not passed to NewInvertedIndex; a config that was decoded after index construction so the map and config diverge; custom code that bypasses the Search entry validation.

Related errors


AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09). Data as JSON: /api/errors/b2ccad1cc54fc52c. Report an issue: GitHub.