How do we script to be able to more than 4000 rows using the forEachResult() method?

To overcome this limitation you can:

  1. Use Search.run().getRange() to iterate the full result set by range, and then iterate the results contained in each range.
  2. Use Search.runPaged()fetch the data for each page and iterate the results. Example:
    var searchObj = searchObjSearch.runPaged({
        pageSize:1000
    });
    searchObj.pageRanges.forEach(function (pageRange) {
        searchObj.fetch({
            index:pageRange.index
        })
        .data.forEach(function (result) {
            //Process each search result here
        });
            csv.push(row);
            row = {};
        });
    });

Leave a comment

Your email address will not be published. Required fields are marked *