This starter ingests Microsoft Entra ID users from Microsoft Graph into Elasticsearch using:
msgraph-sdk(Microsoft Graph SDK for Python)elasticsearch(official Elasticsearch Python client)
It uses Graph delta queries so subsequent runs only ingest changes.
- Python 3.10+
- Elasticsearch reachable from this machine
- A Microsoft Entra app registration with application permissions
For the sample users/delta ingestion:
User.Read.All(Application)
After adding permissions, click Grant admin consent.
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
cp .env.example .envFill .env values.
python ingest_graph_users.pyFirst run performs an initial sync. Later runs use the saved delta token in .state/users_delta.json.
curl -s "$ELASTICSEARCH_URL/$ELASTICSEARCH_INDEX/_count" | jq- Uses stable document IDs (
id) to upsert users. - Handles deleted users from delta stream by issuing Elasticsearch delete operations.
- For production use, run this script on a schedule (cron, Airflow, etc.) and add structured logging/alerting.