In the map reduce script how to execute if more then 4000 results using the range.

In the map reduce script we can execute only 4000 results per execution using this Methode we can lode more then 4000 results.

 var searchResultCount = itemSearchObj.runPaged().count;
                log.debug("itemSearchObj result count",searchResultCount);
               //for getting more than 4000 results


                var searchResults = [];
                var result;
                var singleresult;
                var start = 0, end=1000 ;
                var group={};
                if(searchResultCount<1000)
                {
                    end=searchResultCount;
                }
                for (var i = 0; i < Math.ceil(searchResultCount / 1000); i++)
                {
                    result = itemSearchObj.run().getRange({
                        start: start,
                        end: end
                    });
                    for (var j = 0; j < result.length; j++) {
                        singleresult = result[j];
                        searchResults.push(singleresult);
                    }
                    start = end;
                    end = end + 1000;
                }
                if (searchResultCount > 0) {
                    for (var i = 0; i < searchResults.length; i++) {
                       var columns = itemSearchObj.columns;
                        var singleItem ={};
                        var item =searchResults[i].getValue({
                            name: "internalid", label: "Internal ID"
                        });
                        itemsArray.push(item);
                    }
                }
                log.debug("itemsArray",itemsArray);
                return itemsArray;

Leave a comment

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