> ## Documentation Index
> Fetch the complete documentation index at: https://translations.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> Auth0 のユーザー検索クエリの構文について説明します。

# ユーザー検索クエリの構文

export const AuthCodeGroup = ({children, dropdown}) => {
  const [processedChildren, setProcessedChildren] = useState(children);
  useEffect(() => {
    let unsubscribe = null;
    function init() {
      unsubscribe = window.autorun(() => {
        const processChildren = node => {
          if (typeof node === "string") {
            let processedNode = node;
            for (const [key, value] of window.rootStore.variableStore.values.entries()) {
              const escapedKey = key.replaceAll(/[.*+?^${}()|[\]\\]/g, (String.raw)`\$&`);
              processedNode = processedNode.replaceAll(new RegExp(escapedKey, "g"), value);
            }
            return processedNode;
          } else if (Array.isArray(node)) {
            return node.map(processChildren);
          } else if (node && node.props && node.props.children) {
            return {
              ...node,
              props: {
                ...node.props,
                children: processChildren(node.props.children)
              }
            };
          }
          return node;
        };
        setProcessedChildren(processChildren(children));
      });
    }
    if (window.rootStore) {
      init();
    } else {
      window.addEventListener("adu:storeReady", init);
    }
    return () => {
      window.removeEventListener("adu:storeReady", init);
      unsubscribe?.();
    };
  }, [children]);
  return <CodeGroup dropdown={dropdown}>{processedChildren}</CodeGroup>;
};

export const AuthCodeBlock = ({filename, icon, language, highlight, children}) => {
  const [displayText, setDisplayText] = useState(children);
  const [copyText, setCopyText] = useState(children);
  const wrapperRef = React.useRef(null);
  useEffect(() => {
    let unsubscribe = null;
    function init() {
      if (!window.autorun || !window.rootStore) {
        return;
      }
      unsubscribe = window.autorun(() => {
        let processedChildrenForDisplay = children;
        let processedChildrenForCopy = children;
        for (const [key, value] of window.rootStore.variableStore.values.entries()) {
          const escapedKey = key.replaceAll(/[.*+?^${}()|[\]\\]/g, (String.raw)`\$&`);
          let displayValue = value;
          if (key === "{yourClientSecret}" && value !== "{yourClientSecret}") {
            displayValue = value.substring(0, 3) + "*****マスク済み*****";
          }
          processedChildrenForDisplay = processedChildrenForDisplay.replaceAll(new RegExp(escapedKey, "g"), displayValue);
          processedChildrenForCopy = processedChildrenForCopy.replaceAll(new RegExp(escapedKey, "g"), value);
        }
        setDisplayText(processedChildrenForDisplay);
        setCopyText(processedChildrenForCopy);
      });
    }
    if (window.rootStore) {
      init();
    } else {
      window.addEventListener("adu:storeReady", init);
    }
    return () => {
      window.removeEventListener("adu:storeReady", init);
      unsubscribe?.();
    };
  }, [children]);
  useEffect(() => {
    if (!wrapperRef.current) return;
    const originalWriteText = navigator.clipboard.writeText.bind(navigator.clipboard);
    let isOverriding = false;
    const handleClick = e => {
      const button = e.target.closest('[data-testid="copy-code-button"]');
      if (!button || !wrapperRef.current.contains(button)) return;
      isOverriding = true;
      navigator.clipboard.writeText = text => {
        if (isOverriding) {
          isOverriding = false;
          navigator.clipboard.writeText = originalWriteText;
          return originalWriteText(copyText);
        }
        return originalWriteText(text);
      };
      setTimeout(() => {
        if (isOverriding) {
          isOverriding = false;
          navigator.clipboard.writeText = originalWriteText;
        }
      }, 100);
    };
    const wrapper = wrapperRef.current;
    wrapper.addEventListener('click', handleClick, true);
    return () => {
      wrapper.removeEventListener('click', handleClick, true);
      if (navigator.clipboard.writeText !== originalWriteText) {
        navigator.clipboard.writeText = originalWriteText;
      }
    };
  }, [copyText]);
  return <div ref={wrapperRef}>
      <CodeBlock filename={filename} icon={icon} language={language} lines highlight={highlight}>
        {displayText}
      </CodeBlock>
    </div>;
};

<Callout icon="file-lines" color="#0EA5E9" iconType="regular">
  この内容では、現在の Auth0 ユーザー検索 (バージョン 3) について説明します。
</Callout>

ユーザーを検索する際は、検索を絞り込むために [Lucene query syntax](https://lucene.apache.org/core/2_9_4/queryparsersyntax.html) を使用してクエリを作成できます。

クエリ文字列は、一連の用語と演算子に解析されます。

* 用語には、`jane` や `smith` のような単一の単語を指定できます。
* 用語には、二重引用符で囲まれたフレーズ (`"green apple"`) を指定することもでき、この場合、フレーズ内のすべての単語が同じ順序で一致します。
* フィールド名のない用語は、[ユーザーメタデータ](/ja/docs/manage-users/user-accounts/metadata) フィールド内のテキストには一致しません。
* 複数の用語は、丸括弧でグループ化してサブクエリを作成できます。
* 正規化されたユーザーフィールド (`email`、`name`、`given_name`、`family_name`、`nickname`) の検索値では、大文字と小文字は区別されません。それ以外のすべてのフィールド (`app_metadata` / `user_metadata` のすべてのフィールドを含む) では、大文字と小文字が区別されます。
* 演算子 (`AND`、`OR`、`NOT`) は、すべての正規化されたユーザーフィールドとルートメタデータフィールドで使用できます。
* 演算子は必ず大文字で指定してください。

<div id="searchable-fields">
  ## 検索可能なフィールド
</div>

[正規化されたユーザープロフィール フィールド](/ja/docs/manage-users/user-accounts/user-profiles/normalized-user-profile-schema) と以下のフィールドを使用して、ユーザーを検索できます。

| 検索フィールド           | データ型                         | 説明                                                                                                                                                           |
| ----------------- | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `phone_number`    | text                         | ユーザーの電話番号。SMS 接続のユーザーに対してのみ有効です。                                                                                                                             |
| `phone_verified`  | boolean                      | `true/false` の値は、ユーザーの電話番号が確認済みかどうかを示します。SMS 接続のユーザーに対してのみ有効です。                                                                                              |
| `logins_count`    | integer                      | ユーザーのログイン回数。ユーザーがブロックされている状態でログインした場合、そのブロックされたセッションも `logins_count` にカウントされ、`last_login` の値も更新されます。                                                         |
| `created_at`      | date time                    | ユーザープロフィールが最初に作成された日時のタイムスタンプ。                                                                                                                               |
| `updated_at`      | date time                    | ユーザーのプロフィールが最後に更新または変更された日時のタイムスタンプ。                                                                                                                         |
| `last_login`      | date time                    | ユーザーが最後にログインした日時のタイムスタンプ。このプロパティを `user` オブジェクトとともに [Rules](/ja/docs/customize/rules) 内から参照する場合、その値はその Rule をトリガーしたログインに対応します (Rules は実際のログイン後に実行されるため) 。    |
| `last_ip`         | text (valid IP address)      | ユーザーの最後のログインに関連付けられた IP アドレス。                                                                                                                                |
| `blocked`         | boolean                      | `true` または `false` の値は、ユーザーがブロックされているかどうかを示します。注: `true` で返されるのは Admin Dashboard と Management API によってブロックされたユーザー*のみ*であり、ブルートフォース異常検知によってブロックされたユーザーは返されません。 |
| `email.domain`    | text                         | ユーザーのメールアドレスのドメイン部分。                                                                                                                                         |
| `organization_id` | text (valid organization ID) | ユーザーがメンバーである組織。                                                                                                                                              |

メタデータフィールドでは、以下の型を使用できます。

* boolean
* 数値: integer または double
* text
* オブジェクト: 別のオブジェクト内にネストされたスカラー値を検索するには、そのフィールドへのパスを使用します。例: `app_metadata.subscription.plan:"gold"`
* 配列: 配列内のオブジェクトにネストされたフィールドを検索するには、そのフィールドへのパスを使用し、配列レベルは無視します。例: `user_metadata.addresses.city:"Paris"`

空の配列、空のオブジェクト、または `null` 値を含むメタデータフィールドはインデックス化されないため、検索できません。

`user_metadata` フィールドでは、範囲検索とワイルドカード検索は使用できません。

<div id="exact-match">
  ## 完全一致
</div>

完全一致を検索するには、二重引用符を使用します。`name:"jane smith"`。

たとえば、名前が `jane smith` のユーザーを検索するには、`q=name:"jane smith"` を使用します。

<AuthCodeGroup>
  ```bash cURL theme={null}
  curl --request GET \
    --url 'https://{yourDomain}/api/v2/users?q=name%3A%22jane%20smith%22&search_engine=v3' \
    --header 'authorization: Bearer {yourMgmtApiAccessToken}'
  ```

  ```csharp C# theme={null}
  var client = new RestClient("https://{yourDomain}/api/v2/users?q=name%3A%22jane%20smith%22&search_engine=v3");
  var request = new RestRequest(Method.GET);
  request.AddHeader("authorization", "Bearer {yourMgmtApiAccessToken}");
  IRestResponse response = client.Execute(request);
  ```

  ```go Go theme={null}
  package main

  import (
  	"fmt"
  	"net/http"
  	"io/ioutil"
  )

  func main() {

  	url := "https://{yourDomain}/api/v2/users?q=name%3A%22jane%20smith%22&search_engine=v3"

  	req, _ := http.NewRequest("GET", url, nil)

  	req.Header.Add("authorization", "Bearer {yourMgmtApiAccessToken}")

  	res, _ := http.DefaultClient.Do(req)

  	defer res.Body.Close()
  	body, _ := ioutil.ReadAll(res.Body)

  	fmt.Println(res)
  	fmt.Println(string(body))

  }
  ```

  ```java Java theme={null}
  HttpResponse<String> response = Unirest.get("https://{yourDomain}/api/v2/users?q=name%3A%22jane%20smith%22&search_engine=v3")
    .header("authorization", "Bearer {yourMgmtApiAccessToken}")
    .asString();
  ```

  ```javascript Node.JS theme={null}
  var axios = require("axios").default;

  var options = {
    method: 'GET',
    url: 'https://{yourDomain}/api/v2/users',
    params: {q: 'name:"jane smith"', search_engine: 'v3'},
    headers: {authorization: 'Bearer {yourMgmtApiAccessToken}'}
  };

  axios.request(options).then(function (response) {
    console.log(response.data);
  }).catch(function (error) {
    console.error(error);
  });
  ```

  ```php PHP theme={null}
  $curl = curl_init();

  curl_setopt_array($curl, [
    CURLOPT_URL => "https://{yourDomain}/api/v2/users?q=name%3A%22jane%20smith%22&search_engine=v3",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "GET",
    CURLOPT_HTTPHEADER => [
      "authorization: Bearer {yourMgmtApiAccessToken}"
    ],
  ]);

  $response = curl_exec($curl);
  $err = curl_error($curl);

  curl_close($curl);

  if ($err) {
    echo "cURL Error #:" . $err;
  } else {
    echo $response;
  }
  ```

  ```python Python theme={null}
  import http.client

  conn = http.client.HTTPSConnection("")

  headers = { 'authorization': "Bearer {yourMgmtApiAccessToken}" }

  conn.request("GET", "/{yourDomain}/api/v2/users?q=name%3A%22jane%20smith%22&search_engine=v3", headers=headers)

  res = conn.getresponse()
  data = res.read()

  print(data.decode("utf-8"))
  ```

  ```ruby Ruby theme={null}
  require 'uri'
  require 'net/http'
  require 'openssl'

  url = URI("https://{yourDomain}/api/v2/users?q=name%3A%22jane%20smith%22&search_engine=v3")

  http = Net::HTTP.new(url.host, url.port)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE

  request = Net::HTTP::Get.new(url)
  request["authorization"] = 'Bearer {yourMgmtApiAccessToken}'

  response = http.request(request)
  puts response.read_body
  ```
</AuthCodeGroup>

<div id="wildcards">
  ## ワイルドカード
</div>

ワイルドカード検索では、アスタリスク文字 (`*`) を使って 0 文字以上を置き換え、用語を検索できます。ワイルドカード検索は `user_metadata` フィールドでは使用できません。

<div id="examples">
  #### 例
</div>

* `name:john*` は、名前が `john` で始まるすべてのユーザーを返します。
* `name:j*` は、名前が `j` で始まるすべてのユーザーを返します。
* `q=name:john*` は、名前が `john` で始まるすべてのユーザーを返します。
* 接尾辞一致の場合、リテラルは 3 文字以上である必要があります。たとえば、`name:*usa`` は使用できますが、`name:\*sa\` は使用できません。

<AuthCodeGroup>
  ```bash cURL theme={null}
  curl --request GET \
    --url 'https://{yourDomain}/api/v2/users?q=name%3Ajohn*&search_engine=v3' \
    --header 'authorization: Bearer {yourMgmtApiAccessToken}'
  ```

  ```csharp C# theme={null}
  var client = new RestClient("https://{yourDomain}/api/v2/users?q=name%3Ajohn\*&search_engine=v3");
  var request = new RestRequest(Method.GET);
  request.AddHeader("authorization", "Bearer {yourMgmtApiAccessToken}");
  IRestResponse response = client.Execute(request);
  ```

  ```go Go theme={null}
  package main

  import (
  	"fmt"
  	"net/http"
  	"io/ioutil"
  )

  func main() {

  	url := "https://{yourDomain}/api/v2/users?q=name%3Ajohn*&search_engine=v3"

  	req, _ := http.NewRequest("GET", url, nil)

  	req.Header.Add("authorization", "Bearer {yourMgmtApiAccessToken}")

  	res, _ := http.DefaultClient.Do(req)

  	defer res.Body.Close()
  	body, _ := ioutil.ReadAll(res.Body)

  	fmt.Println(res)
  	fmt.Println(string(body))

  }
  ```

  ```java Java theme={null}
  HttpResponse<String> response = Unirest.get("https://{yourDomain}/api/v2/users?q=name%3Ajohn*&search_engine=v3")
    .header("authorization", "Bearer {yourMgmtApiAccessToken}")
    .asString();
  ```

  ```javascript Node.JS theme={null}
  var axios = require("axios").default;

  var options = {
    method: 'GET',
    url: 'https://{yourDomain}/api/v2/users',
    params: {q: 'name:john*', search_engine: 'v3'},
    headers: {authorization: 'Bearer {yourMgmtApiAccessToken}'}
  };

  axios.request(options).then(function (response) {
    console.log(response.data);
  }).catch(function (error) {
    console.error(error);
  });
  ```

  ```php PHP theme={null}
  $curl = curl_init();

  curl_setopt_array($curl, [
    CURLOPT_URL => "https://{yourDomain}/api/v2/users?q=name%3Ajohn*&search_engine=v3",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "GET",
    CURLOPT_HTTPHEADER => [
      "authorization: Bearer {yourMgmtApiAccessToken}"
    ],
  ]);

  $response = curl_exec($curl);
  $err = curl_error($curl);

  curl_close($curl);

  if ($err) {
    echo "cURL Error #:" . $err;
  } else {
    echo $response;
  }
  ```

  ```python Python theme={null}
  import http.client

  conn = http.client.HTTPSConnection("")

  headers = { 'authorization': "Bearer {yourMgmtApiAccessToken}" }

  conn.request("GET", "/{yourDomain}/api/v2/users?q=name%3Ajohn*&search_engine=v3", headers=headers)

  res = conn.getresponse()
  data = res.read()

  print(data.decode("utf-8"))
  ```

  ```ruby Ruby theme={null}
  require 'uri'
  require 'net/http'
  require 'openssl'

  url = URI("https://{yourDomain}/api/v2/users?q=name%3Ajohn*&search_engine=v3")

  http = Net::HTTP.new(url.host, url.port)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE

  request = Net::HTTP::Get.new(url)
  request["authorization"] = 'Bearer {yourMgmtApiAccessToken}'

  response = http.request(request)
  puts response.read_body
  ```
</AuthCodeGroup>

<div id="ranges">
  ## 範囲
</div>

ユーザー検索クエリでは範囲を使用できます。範囲検索はユーザーメタデータフィールドでは使用できません。

* 包含範囲には角括弧を使用します: `[min TO max]`。
* 排他範囲には波括弧を使用します: `{min TO max}`。
* 波括弧と角括弧は、同じ範囲式内で組み合わせて使用できます: `logins_count:[100 TO 200}`。
* 範囲はワイルドカードと組み合わせて使用できます。たとえば、ログイン回数が 100 回を超えるすべてのユーザーを検索するには、`q=logins_count:{100 TO *]` を使用します。

<AuthCodeGroup>
  ```bash cURL theme={null}
  curl --request GET \
    --url 'https://{yourDomain}/api/v2/users?q=logins_count%3A%7B100%20TO%20*%5D&search_engine=v3' \
    --header 'authorization: Bearer {yourMgmtApiAccessToken}'
  ```

  ```csharp C# theme={null}
  var client = new RestClient("https://{yourDomain}/api/v2/users?q=logins_count%3A%7B100%20TO%20\*%5D&search_engine=v3");
  var request = new RestRequest(Method.GET);
  request.AddHeader("authorization", "Bearer {yourMgmtApiAccessToken}");
  IRestResponse response = client.Execute(request);
  ```

  ```go Go theme={null}
  package main

  import (
  	"fmt"
  	"net/http"
  	"io/ioutil"
  )

  func main() {

  	url := "https://{yourDomain}/api/v2/users?q=logins_count%3A%7B100%20TO%20*%5D&search_engine=v3"

  	req, _ := http.NewRequest("GET", url, nil)

  	req.Header.Add("authorization", "Bearer {yourMgmtApiAccessToken}")

  	res, _ := http.DefaultClient.Do(req)

  	defer res.Body.Close()
  	body, _ := ioutil.ReadAll(res.Body)

  	fmt.Println(res)
  	fmt.Println(string(body))

  }
  ```

  ```java Java theme={null}
  HttpResponse<String> response = Unirest.get("https://{yourDomain}/api/v2/users?q=logins_count%3A%7B100%20TO%20*%5D&search_engine=v3")
    .header("authorization", "Bearer {yourMgmtApiAccessToken}")
    .asString();
  ```

  ```javascript Node.JS theme={null}
  var axios = require("axios").default;

  var options = {
    method: 'GET',
    url: 'https://{yourDomain}/api/v2/users',
    params: {q: 'logins_count:{100 TO *]', search_engine: 'v3'},
    headers: {authorization: 'Bearer {yourMgmtApiAccessToken}'}
  };

  axios.request(options).then(function (response) {
    console.log(response.data);
  }).catch(function (error) {
    console.error(error);
  });
  ```

  ```php PHP theme={null}
  $curl = curl_init();

  curl_setopt_array($curl, [
    CURLOPT_URL => "https://{yourDomain}/api/v2/users?q=logins_count%3A%7B100%20TO%20*%5D&search_engine=v3",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "GET",
    CURLOPT_HTTPHEADER => [
      "authorization: Bearer {yourMgmtApiAccessToken}"
    ],
  ]);

  $response = curl_exec($curl);
  $err = curl_error($curl);

  curl_close($curl);

  if ($err) {
    echo "cURL Error #:" . $err;
  } else {
    echo $response;
  }
  ```

  ```python Python theme={null}
  import http.client

  conn = http.client.HTTPSConnection("")

  headers = { 'authorization': "Bearer {yourMgmtApiAccessToken}" }

  conn.request("GET", "/{yourDomain}/api/v2/users?q=logins_count%3A%7B100%20TO%20*%5D&search_engine=v3", headers=headers)

  res = conn.getresponse()
  data = res.read()

  print(data.decode("utf-8"))
  ```

  ```ruby Ruby theme={null}
  require 'uri'
  require 'net/http'
  require 'openssl'

  url = URI("https://{yourDomain}/api/v2/users?q=logins_count%3A%7B100%20TO%20*%5D&search_engine=v3")

  http = Net::HTTP.new(url.host, url.port)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE

  request = Net::HTTP::Get.new(url)
  request["authorization"] = 'Bearer {yourMgmtApiAccessToken}'

  response = http.request(request)
  puts response.read_body
  ```
</AuthCodeGroup>

<div id="searchable-profile-attribute-examples">
  ## 検索可能なプロフィール属性の例
</div>

Auth0 の<Tooltip tip="Management API: お客様が管理タスクを実行するための製品。" cta="用語集を見る" href="/ja/docs/glossary?term=Management+API">Management API</Tooltip>でユーザーを検索する場合、`user_metadata` または `app_metadata` を使ってユーザーを絞り込めます。そのためには、`q` パラメーターで Lucene Search Syntax を使用します。

Auth0 Management API の[ユーザーの一覧取得または検索](https://auth0.com/docs/api/management/v2#!/Users/get_users)エンドポイントは、結果が 1000 件 (100 件ずつの 10 ページ) までに制限されているため、絞り込みを行うことで、関連性の高い結果を確実に返しやすくなります。

以下は、ユーザープロフィールの `user_metadata` のサンプルです。

```json lines theme={null}
{
  "favorite_color": "blue",
  "approved": false,
  "preferredLanguage": "en",
  "preferences": {
    "fontSize": 13
  },
  "addresses":{
    "city":["Paris","Seattle"]
  }
}
```

<div id="filter-metadata-attributes">
  ### メタデータ属性でフィルタリングする
</div>

`user_metadata` の値を返すには、属性フィルターを含めるように `q` クエリを更新します。

`user_metadata` の値については、プロファイルを直接クエリできます。

`q: _exists_:user_metadata.fav_color`

このクエリは、`user_metadata` に `fav_color` 属性を持つすべてのユーザープロファイルを返します。

<div id="filter-metadata-nested-object-attributes-and-values">
  ### メタデータ のネストされたオブジェクトの属性と値でフィルタリングする
</div>

`user_metadata` 内のネストされたオブジェクトも検索できます。

`q: _exists_:user_metadata.preferences.fontSize`

このクエリは、`user_metadata` に `preferences.fontSize` が設定されているすべてのユーザープロファイルを検索します。

別のオブジェクト内にあるネストされたオブジェクトの値を検索するには、次のクエリを確認してください。

`q: user_metadata.preferences.fontSize:13`

このクエリは、`fontSize` 属性の値が `13` のすべてのユーザープロファイルを返します。

<div id="filter-metadata-nested-array-values">
  ### メタデータ内のネストされた配列の値をフィルタリングする
</div>

ネストされた配列内のフィールドを検索するには、以下のクエリを使用できます。

`q: user_metadata.addresses.city:"Seattle"`

これにより、`user_metadata` の `address.city` 属性の値が `Seattle` であるすべてのユーザープロファイルが返されます。

<div id="learn-more">
  ## 詳しく知る
</div>

* [検索結果を並べ替える](/ja/docs/manage-users/user-search/sort-search-results)
* [ページ単位で検索結果を表示する](/ja/docs/manage-users/user-search/view-search-results-by-page)
* [Get Users エンドポイントを使用してユーザーを取得する](/ja/docs/manage-users/user-search/retrieve-users-with-get-users-endpoint)
