# Get Users With More Than One Account in the Same Source

**URL:** <https://developer.sailpoint.com/discuss/t/get-users-with-more-than-one-account-in-the-same-source/338>\
**Category:** SHF Discussion and Questions\
**Created:** [March 24, 2021, 4:03pm UTC](https://developer.sailpoint.com/discuss/t/get-users-with-more-than-one-account-in-the-same-source/338 "2021-03-24T16:03:18Z")\
**Posts on this page:** 1\
**Showing post:** 13

<div class="post-metadata">

**Author:** ![colin\_mckibben](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/colin_mckibben/32/37182_2.png) [@colin\_mckibben](https://developer.sailpoint.com/discuss/u/colin_mckibben)\
**Post date:** [November 17, 2022, 1:54pm UTC](https://developer.sailpoint.com/discuss/t/get-users-with-more-than-one-account-in-the-same-source/338/13 "2022-11-17T13:54:38Z")

</div>

The query above will only work when limiting by authoritative source. The reason for this is that the top level `source` object on an identity object is that identity’s authoritative source. If you need to restrict your query to a non-authoritative source, then you will need to use the following query.

```json
{
    "query": {
        "query": "@accounts(source.id:2c918088814e6a610181686b56977fa8)"
    },
    "indices": [
        "identities"
    ],
    "aggregationsDsl": {
        "accounts": {
            "nested": {
                "path": "accounts"
            },
            "aggs": {
                "source_id": {
                    "terms": {
                        "field": "accounts.source.id",
                        "min_doc_count": 2,
                        "size": 1000
                    },
                    "aggs": {
                        "identities": {
                            "terms": {
                                "field": "_id",
                                "min_doc_count": 2
                            },
                            "aggs": {
                                "accounts": {
                                    "top_hits": {}
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

```

There are many other ways to narrow down your search, as documented in the [searchable fields guide](https://documentation.sailpoint.com/saas/help/search/searchable-fields.html#first-level-fields-for-identities).

---

_[View the full topic](https://developer.sailpoint.com/discuss/t/get-users-with-more-than-one-account-in-the-same-source/338)._
