Microsoft Search API を使用して Outlook メッセージを検索する

Microsoft Graph の Microsoft Search API を使用して、メール メッセージ内の情報を検索し、関連性でランク付けされたメッセージを返し、専用の検索エクスペリエンスをレンダリングします。 この検索は、サインインしているユーザー自身のメールボックス内のメッセージの本文と添付ファイルに適用されます。

注意

検索 API スキーマがベータ版で変更されました。 検索要求と応答の一部のプロパティの名前が変更または削除されました。 詳細については、「 スキーマ変更の非推奨の警告」を参照してください。 このトピックの例では、最新のスキーマを示します。

検索クエリには、エンド ユーザーが Outlook の [Search] テキスト ボックスに入力するフィルターを含めることができます。

メッセージ検索結果は 、receivedDateTime で降順に並べ替えられます。

メッセージ検索は、職場または学校のアカウントに適用されます。 ユーザーは自分のメールボックスを検索できますが、委任されたメールボックスを検索することはできません。 詳細については、「 既知の制限事項」を参照してください。

メッセージ検索では、添付ファイルも検索されます。 メッセージ添付ファイル検索で サポートされているファイルの種類 は、SharePoint Online 検索のファイルと同じです。

例 1: ユーザーのメールボックス内のメッセージをSearchする

次の例では、サインインしているユーザーのメールボックス内のメッセージに対して、メッセージの任意の部分 (送信者名、件名、メッセージ本文、または添付ファイル) に "contoso" という文字列を含むクエリを実行します。 クエリは最初の 25 件の結果を返します。 検索結果は DateTime 降順で並べ替えます。

要求

POST https://graph.microsoft.com/v1.0/search/query
Content-Type: application/json

{
  "requests": [
    {
      "entityTypes": [
        "message"
      ],
      "query": {
        "queryString": "contoso"
      },
      "from": 0,
      "size": 25
    }
  ]
}

応答

検索基準に一致する 1 つのメッセージを含む応答の例を次に示します。

HTTP/1.1 200 OK
Content-type: application/json

{
  "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#search",
  "value": [
    {
      "searchTerms": [
        "contoso"
      ],
      "hitsContainers": [
        {
          "total": 1,
          "moreResultsAvailable": false,
          "hits": [
            {
              "hitId": "ptWLQ4o6HYpQg8xmAAATzOzRAAA=",
              "rank": 1,
              "summary": "Here is a summary of your messages from last week",
              "resource": {
                "@odata.type": "#microsoft.graph.message",
                "createdDateTime": "2019-10-07T10:00:08Z",
                "lastModifiedDateTime": "2019-10-07T10:00:11Z",
                "receivedDateTime": "2019-10-07T10:00:09Z",
                "sentDateTime": "2019-10-07T09:59:52Z",
                "hasAttachments": false,
                "subject": "Weekly digest: Microsoft 365 changes",
                "bodyPreview": "Here is a summary of your messages from last week -   New Feature: Live captions in English-US a",
                "importance": "normal",
                "replyTo": [
                  {
                    "emailAddress": {
                      "name": "Goncalo Torres"
                    }
                  }
                ],
                "sender": {
                  "emailAddress": {
                    "name": "Office365 Message Center",
                    "address": "gtorres@contoso.com"
                  }
                },
                "from": {
                  "emailAddress": {
                    "name": "Office365 Message Center",
                    "address": "gtorres@contoso.com"
                  }
                }
              }
            }
          ]
        }
      ]
    }
  ]
}

例 2: 上位の結果メッセージをSearchする

次の例では、例 1 に示す検索クエリを使用し、結果を関連性で並べ替えます。

要求

POST https://graph.microsoft.com/v1.0/search/query
Content-Type: application/json

{
  "requests": [
    {
      "entityTypes": [
        "message"
      ],
      "query": {
        "queryString": "contoso"
      },
      "from": 0,
      "size": 15,
      "enableTopResults": true
    }
  ]
}

応答

HTTP/1.1 200 OK
Content-type: application/json

{
  "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#search",
  "value": [
    {
      "searchTerms": [
        "contoso"
      ],
      "hitsContainers": [
        {
          "total": 1,
          "moreResultsAvailable": false,
          "hits": [
            {
              "hitId": "ptWLQ4o6HYpQg8xmAAATzOzRAAA=",
              "rank": 1,
              "summary": "Here is a summary of your messages from last week",
              "resource": {
                "@odata.type": "#microsoft.graph.message",
                "createdDateTime": "2019-10-07T10:00:08Z",
                "lastModifiedDateTime": "2019-10-07T10:00:11Z",
                "receivedDateTime": "2019-10-07T10:00:09Z",
                "sentDateTime": "2019-10-07T09:59:52Z",
                "hasAttachments": false,
                "subject": "Weekly digest: Microsoft 365 changes",
                "bodyPreview": "Here is a summary of your messages from last week -   New Feature: Live captions in English-US a",
                "importance": "normal",
                "replyTo": [
                  {
                    "emailAddress": {
                      "name": "Goncalo Torres"
                    }
                  }
                ],
                "sender": {
                  "emailAddress": {
                    "name": "Office365 Message Center",
                    "address": "gtorres@contoso.com"
                  }
                },
                "from": {
                  "emailAddress": {
                    "name": "Office365 Message Center",
                    "address": "gtorres@contoso.com"
                  }
                }
              }
            }
          ]
        }
      ]
    }
  ]
}

既知の制限

  • サインインしているユーザー自身のメールボックスにのみアクセスできます。 委任されたメールボックスの検索はサポートされていません。
  • メッセージの場合、searchHitsContainer 型の total プロパティには、一致する結果の合計数ではなく、ページ上の結果の数が含まれます。
  • イベントの並べ替え結果はサポートされていません。 要求の並べ替え句は、応答で不適切な要求エラー コードを返します。

次の手順