500 is the max limit, a defined boundary, of the number of items which will be fetched via Search API in SP Online. It cant be changed via powershell. If you expect more than 500 results, you need to get it via paging.
Search limits for SharePoint Online
If it was SP Onprem, you can increase the max row limit via powershell as below, but will come at some cost to performance:
$ssa = Get-SPEnterpriseSearchServiceApplication
$ssa.MaxRowLimit = 10000
$ssa.Update()
But in SPOnline, we cant modify this limit yet.
Using REST API, you can follow Vadim's excellent gist utility which fetches all search results via paging. As mentioned in Brent's answer, you need to specify the start row when you are going to use paging.
Gist utility:
function search(queryText,rowLimit,startRow,allResults)
{
var allResults = allResults || [];
var url = _spPageContextInfo.siteAbsoluteUrl + "/_api/search/query?querytext='" + queryText + "'&rowlimit=" + rowLimit + "'&startrow=" + startRow;
return $.getJSON(url).then(function(data) {
var relevantResults = data.PrimaryQueryResult.RelevantResults;
allResults = allResults.concat(relevantResults.Table.Rows);
if (relevantResults.TotalRows > startRow + relevantResults.RowCount) {
return search(queryText,rowLimit,startRow+relevantResults.RowCount,allResults);
}
return allResults;
});
}
Usage:
search('some query text',500,0).done(function(results){
//iterate through the results
for(var i = 0;i < results.length;i++){
console.log(results[i]);
}
});
If you thinking of using managed CSOM, then you can use the below method:
private static ResultTable GetSearchResults(int startIndex,ClientContext clientContext)
{
ClientResult<ResultTableCollection> results = null;
try
{
KeywordQuery keywordQuery = new KeywordQuery(clientContext);
SearchExecutor searchExecutor = new SearchExecutor(clientContext);
keywordQuery.StartRow = startIndex;//gets or sets the first row of information from the search results
keywordQuery.QueryText = "queryText here";
keywordQuery.RowLimit = 500;
keywordQuery.RowsPerPage = 500;
keywordQuery.TrimDuplicates = false;
keywordQuery.Timeout = 10000; //10 minutes
// execute the query and load the results into a collection
results = searchExecutor.ExecuteQuery(keywordQuery);
clientContext.ExecuteQuery();
//clientContext.ExecuteQueryWithIncrementalRetry(5, 30000); //5 retries, with a base delay of 30 secs.
return results.Value.FirstOrDefault(v => v.TableType.Equals(KnownTableTypes.RelevantResults));
}
catch (Exception)
{
throw;
}
}
How to use it :
static void Main(string[] args)
{
using (ClientContext clientContext = new ClientContext("https://sitecollectionurl"))
{
#region Build Data Dable
DataTable resultDataTable = new DataTable();
DataColumn titleCol = new DataColumn("Title");
DataColumn pathCol = new DataColumn("Path");
resultDataTable.Columns.Add(titleCol);
resultDataTable.Columns.Add(pathCol);
#endregion
int currentRowIndex = 0;
var resultTable = GetSearchResults(0, clientContext);
if (resultTable != null && resultTable.TotalRowsIncludingDuplicates > 0)
{
while (resultTable.TotalRowsIncludingDuplicates > resultDataTable.Rows.Count)
{
foreach (var resultRow in resultTable.ResultRows)
{
DataRow row = resultDataTable.NewRow();
row["Title"] = resultRow["Title"];
row["Path"] = resultRow["Path"];
resultDataTable.Rows.Add(row);
}
//Update the current row index
currentRowIndex = resultDataTable.Rows.Count;
resultTable = null;
resultTable = GetSearchResults(currentRowIndex, clientContext);
if (resultTable != null && resultTable.TotalRowsIncludingDuplicates > 0)
{
if (resultTable.RowCount <= 0)
break;
}
else
break;
}
}
string totalResults = resultDataTable.Rows.Count;
}
}
Reference - SP 2013 search results paging