How to get all results from azure search?
Asked Answered
I

1

5

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?

Inurn answered 12/10, 2017 at 13:50 Comment(0)
A
10

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.
Avila answered 12/10, 2017 at 14:46 Comment(1)
Hi, thanks for reply. Have another issue for same operation. Please have a look : #46714567Inurn

© 2022 - 2024 — McMap. All rights reserved.