0

Example: I have a content type as FAQ. I need to retrieve only 8 FAQ results (along with other content types - no limit )from Sharepoint search api.

0

Using the REST API, you would have to perform two separate queries, and use your client-side code to concatenate the two result sets together.

The RowLimit parameter will restrict the number of results you get back from the search api, but it is separate/outside of your query, so it will limit the whole result set, not just one aspect of your query. You can retrieve results for a specific content type by using the contenttype filter parameter in your search query text, for example: /_api/search/query?querytext='contenttype:MyFirstContentType'&rowlimit=8 will get the first eight results where the contenttype is "MyFirstContentType", and you can "OR" together your query parameters if you want to specify multiple content types, for example: /_api/search/query?querytext='contenttype:MyFirstContentType OR contenttype:MySecondContentType OR contenttype:MyThirdContentType'&rowlimit=8 will get the first eight results where the contenttype is either "MyFirstContentType" or "MySecondContentType" or "MyThirdContentType".

If you wanted to only get the first eight for "MyFirstContentType", but unlimited of all others, you would need two separate queries similar to the following:

/_api/search/query?querytext='contenttype:MyFirstContentType'&rowlimit=8

and then:

/_api/search/query?querytext='NOT(contenttype:MyFirstContentType)'

| improve this answer | |
  • That's a viable solution , Thanks for that Willman. But is there any other way ? Like when the search results come with refiners, it will have values such as Content Type => MyFirstContentType (x), where x refers to the number of MyFirstContentType items. Is there a way to restrict there itself from returning only required x items ? – Puru Jan 6 at 8:55
  • You can control the refiners more closely (see this for the syntax for refiners, and this shows how to apply that syntax to a REST query), but even if you specify a limit to the Content Type refiner, that would restrict how many different ContentTypes are in that refiner, not how many results are returned for each individual content type in the refiner. – willman Jan 6 at 13:08
  • Understood willman. Thank you. – Puru Jan 7 at 5:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.