Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get all results from azure search?

Currently I am creating an application where I need to call API for azure search. Calling this API :

https://<searchServiceName>.search.windows.net/indexes/<index-name>/docs/search?api-version=2016-09-01

Also providing all required parameters with search query as :

(test||test||test||test||test||test||test)+ Contacts+Campaigns+Companies+Targets+Complanits+Claims+Activities+Opportunities+Completed Activities

Problem is , there are total 1127 rows in table related to this particular search. But I get only first fifty of them with following JSON object output.

"@search.nextPageParameters": {
        "search": "(test||test||test||test||test||test||test)+ Contacts+Campaigns+Companies+Targets+Complanits+Claims+Activities+Opportunities+Completed Activities",
        "skip": 50}

What changes I should make in query so that I can get all 1127 or more results?

like image 984
Deva Avatar asked Oct 12 '17 13:10

Deva


1 Answers

This is expected behavior. From the documentation (See documentation about $top query parameter):

$top=# (optional)

The number of search results to retrieve. This defaults to 50. When calling via POST, this parameter is named top instead of $top. If you specify a value greater than 1000 and there are more than 1000 results, only the first 1000 results will be returned, along with a link to the next page of results (see @odata.nextLink in the example below).

Azure Search uses server-side paging to prevent queries from retrieving too many documents at once. The default page size is 50, while the maximum page size is 1000. This means that by default Search Documents returns at most 50 results if you don't specify $top. If there are more than 50 results, the response includes information to retrieve the next page of at most 50 results (see @odata.nextLink and @search.nextPageParameters in the Examples below. Similarly, if you specify a value greater than 1000 for $top and there are more than 1000 results, only the first 1000 results are returned, along with information to retrieve the next page of at most 1000 results.

Based on this, there are a few things you would need to do:

  1. Specify a value for $top parameter. Because you're not specifying any value, default number of records (which is 50) are returned.
  2. Since a single request can only fetch a maximum of 1000 records and you mentioned that the index contains more than 1000 records, you will need to issue multiple queries to fetch paged results.
like image 159
Gaurav Mantri Avatar answered Nov 09 '22 20:11

Gaurav Mantri