Kql filter on a field value works in Sharepoint search but not search rest api call

matt howell 331 Reputation points

I need to get all news posts from multiple sites where a yes/no field = true. Here's my search rest api call where RefinableString05 is mapped to the yes/no field:

/_api/search/query?querytext='Path:https://xxx.sharepoint.com/sites/site1 OR Path:https://xxx.sharepoint.com/sites/site2/sitepages AND SPContentType:"Site Page" AND RefinableString05:true AND PromotedState:2 AND IsDocument:True AND FileExtension:aspx'&sortlist='FirstPublishedDate:descending'&startRow=0&rowlimit=15&selectproperties='Title,Description,RefinableString05,FirstPublishedDate,PictureThumbnailURL,WebId,Path'

This call returns multiple posts where RefinableString05 is false. If I enter RefinableString05:true in the default search box or include only 1 site in the api call, the results are correct so I'm pretty sure this isn't a managed property or indexing problem.. I've also reindexed sites and waited a few days.

Is my syntax wrong or is there some other way to ensure the filters get applied to 2 or more sites? The "OR" operator is causing the filters to be ignored for the site after "OR", but though repeating all the filters does work, that doesn't seem like a very efficient solution.

A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,212 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,790 questions
0 comments No comments
{count} votes

Accepted answer
  1. MichaelHan-MSFT 18,021 Reputation points

    Hi @matt howell ,

    Yes, it's the best option. If you do not add parentheses, the logic would be like this:

    Path:https://xxx.sharepoint.com/sites/site1 OR (Path:https://xxx.sharepoint.com/sites/site2/sitepages) AND RefinableString05:true'& etc)  

    You would get all the results from site1 and filter results from site2, which are not you want.

    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

1 additional answer

Sort by: Most helpful
  1. matt howell 331 Reputation points

    Tested out wrapping site paths in parentheses and it seems to work - can someone confirm this is the best option?
    ?querytext='(Path:https://xxx.sharepoint.com/sites/site1 OR Path:https://xxx.sharepoint.com/sites/site2/sitepages) AND RefinableString05:true'& etc

    0 comments No comments