Lunr index not found

I’ve had lunr working in my Hugo site for a long time but recently discovered it broken, not returning results, and I’m working backward to understand what went wrong.

Hugo version is 0.76.0
Lunr is 2.2.1

config.toml includes:
home = [“HTML”, “RSS”, “JSON”]
page = [“HTML”]
section = [“HTML”, “RSS”]

an index.json file is generated in the site root: public/index.json
the contents of index.json are valid JSON

the problem appears to be that the index.json loaded for query processing is empty. The script the gets the index is:

    // Initialize lunrjs using our generated index file
    function initLunr() {
       console.log("initLunr: " + "{{ "index.json" | absURL }}");
			 $.getJSON("{{ "index.json" | absURL }}")
            .done(function(index) {
                pagesIndex = index;
                console.log("index:", index);
                lunrIndex = lunr(function() {
                    this.field("title", { boost: 10 });
                    this.field("categories", { boost: 5 });

                    pagesIndex.forEach(function (page) {
                    }, this)
            .fail(function(jqxhr, textStatus, error) {
                var err = textStatus + ", " + error;
                console.error("Error fetching Hugo search index JSON file:", err);

Here’s the console log showing that we’re attempting to load the index from the site root:

And here’s that URL loaded in a browser window

Note that it is a 200 response of an empty set - just [ ].

Here’s the public directory to the site, showing the index.json file at root.

What do I do next to tease more information out of this situation?

Apparently the index should be under /layouts, not a site root. I moved the search index to layouts:

cp public/index.json layouts/

and now lunr search results are working again.

So I think the next question is: where are we telling lunr where to put the generated index?

just backing my way into seeing how the pieces fit together:

the lunr index is generated from a template:

  {{- range $index, $page := .Site.RegularPages -}}
    {{- if gt $index 0 -}} , {{- end -}}
    {{- $entry := dict "uri" $page.RelPermalink "title" $page.Title -}}
    {{- $entry = merge $entry (dict "content" ($page.Plain | htmlUnescape)) -}}
    {{- $entry = merge $entry (dict "description" $page.Description) -}}
    {{- $entry = merge $entry (dict "categories" $page.Params.categories) -}}
    {{- $entry = merge $entry (dict "tags" $page.Params.tags) -}}
    {{- $entry | jsonify -}}
  {{- end -}}

So the whole bit in the post above about copying the generated index.json to the layouts directory works in the sense that it gives results, the template here works and seems like the right approach.