コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
クエリ結果の数を取得する
matters.count
メソッドを使用すると、エクスポートを作成する前に、Gmail または Google グループのクエリからメッセージをカウントできます。この情報を使用して、クエリフィルタを調整し、結果の数を増減できます。
Vault リソースを使用するには、アカウントに必要な Vault 権限と案件へのアクセス権が必要です。案件にアクセスするには、アカウントが案件を作成したか、案件が共有されているか、[全案件の閲覧] 権限を持っている必要があります。
次の例は、次の条件を満たすメッセージのクエリで返された結果をカウントする方法を示しています。
- アカウント
email1
と email2
が所有するメッセージ。
- 下書きメールは除外されます。
ceo@solarmora.com
に送信されたメッセージ。
Java
public Long count(Vault client, String matterId) {
AccountInfo emailsToSearch = new AccountInfo().setEmails(ImmutableList.of("email1", "email2"));
MailOptions mailQueryOptions = new MailOptions().setExcludeDrafts(true);
String queryTerms = "to:ceo@solarmora.com";
Query query =
new Query()
.setCorpus("MAIL")
.setDataScope("ALL_DATA")
.setSearchMethod("ACCOUNT")
.setAccountInfo(emailsToSearch)
.setTerms(queryTerms);
CountArtifactsRequest request = new CountArtifactsRequest().setQuery(query);
Operation operation = client.matters().count(matterId, request).execute();
while(!operation.getDone()) {
sleep(2000);
operation = service.operations().get(operation.getName()).execute();
}
if(operation.getResponse() != null) {
return Long.parseLong(operation.getResponse.get("total_count").toString());
}
return -1;
}
Python
def count(service, matter_id):
emails_to_search = ['email1', 'email2']
mail_query_options = {'excludeDrafts': True}
query_terms = 'to:ceo@solarmora.com'
mail_query = {
'corpus': 'MAIL',
'dataScope': 'ALL_DATA',
'searchMethod': 'ACCOUNT',
'accountInfo': {
'emails': emails_to_search
},
'terms': query_terms,
'mailOptions': mail_query_options,
}
request = {
'query': mail_query
}
operation = service.matters().count(matterId=matter_id, body=request).execute()
while not operation.getDone():
time.sleep(2)
operation = service.operations().get(name=operation.getName()).execute()
if operation.getResponse() is None:
return -1
return operation.getResponse()["total_count"]
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-08-29 UTC。
[null,null,["最終更新日 2025-08-29 UTC。"],[],[],null,["Count query results\n-------------------\n\nYou can use the `matters.count` method to count the messages from a Gmail or Groups query before you create an export. With this information, you can refine your query filters to return more or less results.\n\nTo work with Vault resources, the account must have the [required Vault\nprivileges](https://support.google.com/vault/answer/2799699) and access to the\nmatter. To access a matter, the account must have created the matter, have the\nmatter shared with them, or have the **View All Matters** privilege.\n\nThe following example shows how to count the results returned by a query for messages that meet the following criteria:\n\n- messages owned by accounts `email1` and `email2`.\n- excludes draft messages.\n- messages sent to `ceo@solarmora.com`.\n\n### Java\n\n```java\npublic Long count(Vault client, String matterId) {\n AccountInfo emailsToSearch = new AccountInfo().setEmails(ImmutableList.of(\"email1\", \"email2\"));\n MailOptions mailQueryOptions = new MailOptions().setExcludeDrafts(true);\n String queryTerms = \"to:ceo@solarmora.com\";\n Query query =\n new Query()\n .setCorpus(\"MAIL\")\n .setDataScope(\"ALL_DATA\")\n .setSearchMethod(\"ACCOUNT\")\n .setAccountInfo(emailsToSearch)\n .setTerms(queryTerms);\n CountArtifactsRequest request = new CountArtifactsRequest().setQuery(query);\n Operation operation = client.matters().count(matterId, request).execute();\n\n while(!operation.getDone()) {\n sleep(2000);\n operation = service.operations().get(operation.getName()).execute();\n }\n if(operation.getResponse() != null) {\n return Long.parseLong(operation.getResponse.get(\"total_count\").toString());\n }\n return -1;\n}\n \n```\n\n### Python\n\n```python\ndef count(service, matter_id):\n emails_to_search = ['email1', 'email2']\n mail_query_options = {'excludeDrafts': True}\n query_terms = 'to:ceo@solarmora.com'\n mail_query = {\n 'corpus': 'MAIL',\n 'dataScope': 'ALL_DATA',\n 'searchMethod': 'ACCOUNT',\n 'accountInfo': {\n 'emails': emails_to_search\n },\n 'terms': query_terms,\n 'mailOptions': mail_query_options,\n }\n request = {\n 'query': mail_query\n }\n operation = service.matters().count(matterId=matter_id, body=request).execute()\n\n while not operation.getDone():\n time.sleep(2)\n operation = service.operations().get(name=operation.getName()).execute()\n\n if operation.getResponse() is None:\n return -1\n\n return operation.getResponse()[\"total_count\"]\n \n```"]]