Filter list and items in Microsoft Search API

captain_atharv 511 Reputation points
2022-11-03T11:05:44.48+00:00

Hi,
I'm using Microsoft Search API (https://learn.microsoft.com/en-us/graph/api/search-query?view=graph-rest-1.0).
I'm trying to filter out folders from my search results. On using 'ContentType:Document' in queryString, I'm able to filter out folders but I'm not receiving list items.
Is there a way to filter out only folders? I want my search to return Documents and Lists only.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,124 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,071 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,767 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Srinivasa Rao Darna 6,701 Reputation points Microsoft Vendor
    2022-11-03T11:41:49.417+00:00

    Hello @captain_atharv ,

    As I understand your query, ContentType:Document refers to files "entityTypes": ["driveItem"], and ContentType:Item will be returning listItems "entityTypes": ["listItem"].

    Hope this helps.
    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    0 comments No comments

  2. RaytheonXie_MSFT 32,726 Reputation points Microsoft Vendor
    2022-11-07T06:23:25.74+00:00

    Hi @captain_atharv ,
    Per my test, I do agree with SrinivasaRaoDarna-MSFT's answer. You will need to use "entityTypes": ["listItem"] to return list items. But if you set ContentType:Document in queryString. It will filter out list items too. So we are unable to filter documents and list items in a query currently.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    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.