search - 为 Microsoft Graph 创建一个等效于 "contains"的筛选器查询

标签 search filter odata microsoft-graph-api

我需要创建一个 $filter查询用于在字符串(用户的显示名称)中搜索特定单词的 Microsoft Graph API。

例如,我希望能够找到名称中包含“Esteban”的所有用户:

Luis Esteban
Alphonse Esteban
Esteban Luis
Alphonse Esteban Luis



以下查询有效,但只返回名称中以“Esteban”开头的用户,而不返回包含“Esteban”的用户:
https://graph.microsoft.com/v1.0/users?$filter=startswith(displayName,'Esteban')

我也尝试使用 contains而不是 startswith ,但它给出了错误响应:

{ "error": { "code": "Request_BadRequest", "message": "An unknown function with name 'contains' was found. This may also be a key lookup on a navigation property, which is not allowed.", "innerError": { "request-id": "e5ed5c30-4e62-4497-8976-1d38167e759d", "date": "2018-09-13T23:17:17" } } }



即使 Microsoft Graph docs说他们支持 OData 4.0,他们还说:

"The contains string operator is currently not supported on any Microsoft Graph resources."



我还尝试了 OData documentation 给出的其他命令和 construction rules应该由 filter 支持的和其他查询参数。

特别是我尝试了这些命令的组合:

startswith
endswith
indexof
substring



但没有成功。似乎 MS Graph API 不支持除 startswith 之外的任何内容。无论如何。

我尝试了 v1.0 和 API 的 beta 端点。

有没有其他方法,MS Graph API 支持的 OData 4.0 命令和/或查询参数的一些智能组合,允许搜索等效于 contains ?

PS:您可以使用 Graph Explorer here 尝试查询.

最佳答案

如您所知,Graph API 现在不支持您的要求。我的建议是先获取用户列表,然后进行内存过滤。这种方式也适用于其他不支持的 Graph API。

同时,请务必投票支持 existing feature requestUser Voice或提交一个新的。

关于search - 为 Microsoft Graph 创建一个等效于 "contains"的筛选器查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52321911/

相关文章:

java - 二分查找的比较次数

算法优化——多点之间的最短路线

java - 如何使用 Java 在 MongoDB 3 中使用多个过滤器执行文档的批量更新

ruby-on-rails - 'dynamic'搜索的编程语言?

php - MySQL - ORDER BY CASE WHEN 不起作用

exception - 在 Nestjs 服务中抛出的正确异常类型是什么?

filter - Maximo ListView : Filter where field is null OR equals value?

c# - 将 Linq 表达式转换为 URI : The method 'Select' is not supported 时出错

c# - OData 查询中的 LIKE

asp.net-web-api - ASP.NET WebAPI OData - 继承自 EntitySetController<> 但使用 Get(ODataQueryOptions options) 而不是 [Queryable]Get()