<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[How to search for users not registered to a specific application?]]></title><description><![CDATA[<p dir="auto">I need to identify users in FusionAuth who are <strong>not</strong> registered to a particular application. The User Search API supports querying for users with registrations, but how can I construct a query to find users that don't have a registration for a given application ID?</p>
<p dir="auto">Specifically, I want to use the Elasticsearch query syntax to exclude users who have a registration matching a certain <code>applicationId</code>.</p>
]]></description><link>https://fusionauth.io/community/forum/topic/3172/how-to-search-for-users-not-registered-to-a-specific-application</link><generator>RSS for Node</generator><lastBuildDate>Sun, 04 Oct 2026 23:35:42 GMT</lastBuildDate><atom:link href="https://fusionauth.io/community/forum/topic/3172.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 30 Sep 2026 19:13:39 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to search for users not registered to a specific application? on Wed, 30 Sep 2026 19:13:50 GMT]]></title><description><![CDATA[<p dir="auto">You can use the User Search API with a <code>must_not</code> clause in the Elasticsearch query to exclude users registered to a specific application. Here's an example:</p>
<pre><code class="language-bash">curl -X POST https://sandbox.fusionauth.io/api/user/search \
  -H 'Authorization: &lt;your-api-key&gt;' \
  -H 'Content-Type: application/json' \
  -d '{
  "search": {
    "accurateTotal": true,
    "numberOfResults": 100,
    "startRow": 0,
    "query": "{\"bool\":{\"must_not\":[{\"nested\":{\"path\":\"registrations\",\"query\":{\"bool\":{\"must\":[{\"match\":{\"registrations.applicationId\":\"&lt;your-application-id&gt;\"}}]}}}}]}}"
  }
}'
</code></pre>
<p dir="auto"><strong>Key points:</strong></p>
<ul>
<li>The <code>must_not</code> clause excludes users matching the nested query</li>
<li>The <code>nested</code> query targets the <code>registrations</code> path since registrations are nested objects in the Elasticsearch mapping</li>
<li>Inside the nested query, the <code>must</code> clause matches the specific <code>applicationId</code></li>
<li>Replace <code>&lt;your-application-id&gt;</code> with the UUID of your target application</li>
<li>This returns users who either have no registrations at all, or have registrations to other applications but not the specified one</li>
</ul>
<p dir="auto">You can paginate through results using <code>startRow</code> and <code>numberOfResults</code> if you have a large user base.</p>
<p dir="auto"><strong>Important:</strong> This approach requires the <strong>Elasticsearch search engine</strong> (not the database engine). You must use the <code>search.query</code> parameter with raw Elasticsearch JSON when querying against <code>registrations</code>, because it is defined as a <a href="https://www.elastic.co/guide/en/elasticsearch/reference/6.3/nested.html" rel="nofollow ugc">nested datatype</a> in the Elasticsearch mapping. The <code>queryString</code> parameter cannot be used for nested fields like <code>registrations</code> with expected results.</p>
<p dir="auto"><strong>Tip:</strong> You can use the <strong>Admin UI → Users → Advanced → Show Elasticsearch Query</strong> toggle to build and test queries interactively before using them in the API.</p>
<h2>Related Documentation</h2>
<ul>
<li><a href="https://fusionauth.io/docs/apis/users/search#elasticsearch-search-engine" rel="nofollow ugc">User Search API - Elasticsearch Search Engine</a> - Main API reference for searching users with Elasticsearch</li>
<li><a href="https://fusionauth.io/docs/lifecycle/manage-users/search/user-search-with-elasticsearch#searching-with-query" rel="nofollow ugc">Searching Users With Elasticsearch or OpenSearch - Searching With <code>query</code></a> - Guide on using the <code>query</code> parameter for advanced searches</li>
<li><a href="https://fusionauth.io/docs/apis/users/search#additional-query-examples" rel="nofollow ugc">User Search API - Additional Query Examples</a> - Examples of various query patterns including nested queries</li>
<li><a href="https://fusionauth.io/docs/get-started/core-concepts/registrations" rel="nofollow ugc">Registrations</a> - Core concepts documentation explaining the relationship between Users, Applications, and Registrations</li>
<li><a href="https://fusionauth.io/docs/lifecycle/manage-users/search/user-search-with-elasticsearch#field-mappings" rel="nofollow ugc">Field Mappings</a> - Available fields for matching in Elasticsearch searches</li>
</ul>
]]></description><link>https://fusionauth.io/community/forum/post/8681</link><guid isPermaLink="true">https://fusionauth.io/community/forum/post/8681</guid><dc:creator><![CDATA[FASupportBot]]></dc:creator><pubDate>Wed, 30 Sep 2026 19:13:50 GMT</pubDate></item></channel></rss>