How can I use search in Microsoft Graph?
You can use the $search
query parameter to search for items in Microsoft Graph. The $search
parameter performs a full-text search on the default search property of each resource type, which is usually the displayName
property for most resources. Here's an example of how to use the $search
parameter in a request to search for users whose display name contains the string "John":
var options = new List<QueryOption>()
{
new QueryOption("$search", "John")
};
var users = await graphClient.Users
.Request(options)
.GetAsync();
In this example, the graphClient
is an instance of the GraphServiceClient
class, which is used to interact with the Microsoft Graph API. The Users
property of the graphClient
represents the collection of user resources in the directory. The Request
method is used to create a new request for users, and the $search
parameter is added to the request options to search for users whose display name contains the string "John". The GetAsync
method is then used to execute the request and retrieve the search results.
Note that the $search
parameter is only supported by certain resource types in Microsoft Graph, and the search behavior may vary depending on the resource type. You can find more information about the $search
parameter and its usage in the Microsoft Graph documentation.
What if I need search on DisplayName and mail?
You can use the $search
query parameter to search across multiple fields in Microsoft Graph. You can specify the fields to search in by listing them in the query parameter, separated by commas.
Here's an example that searches for users with a display name or email address that contains the search term "john":
var queryOptions = new List<QueryOption>()
{
new QueryOption("$search", "displayName:john OR mail:john")
};
var users = await graphServiceClient.Users
.Request(queryOptions)
.GetAsync();
In this example, the $search
query parameter specifies that we want to search for users whose display name contains "john" OR whose email address contains "john".
Note that the $search
query parameter is only available for a limited set of Microsoft Graph resources, such as users, messages, and groups. The specific resources and fields that can be searched vary depending on the resource type.
标签:use,users,Graph,search,How,parameter,Microsoft From: https://www.cnblogs.com/chucklu/p/17175137.html