main
OpenAlex → Elasticsearch
Bulk-index OpenAlex snapshot data (JSONL/gzip) into Elasticsearch.
Structure
├── elasticsearch/
│ ├── mappings.py # Index mappings & transforms for all 21 entity types
│ └── upload.py # Generic upload script (any entity)
├── requirements.txt
├── openapi.json # OpenAlex OpenAPI 3.1.0 spec (reference)
└── .env # ES_USERNAME, ES_PASSWORD (not committed)
Setup
pip install -r requirements.txt
Configure credentials in .env:
ES_USERNAME=your_user
ES_PASSWORD=your_pass
Or use alternative auth via environment variables:
| Variable | Description |
|---|---|
ES_URL |
Elasticsearch URL (default: http://localhost:9200) |
ES_API_KEY |
ApiKey auth |
ES_BEARER_TOKEN |
JWT bearer token |
ES_USERNAME / ES_PASSWORD |
HTTP Basic auth |
Usage
cd elasticsearch/
# Upload works
python upload.py --entity works --input ../works/
# Upload any entity
python upload.py --entity authors --input ../authors/
python upload.py --entity institutions --input ../institutions/
# Single file
python upload.py --entity awards --input ../awards/part_0000.gz
# Create all 21 indices without uploading
python upload.py --entity works --create-all-indices --create-index-only
# Custom batch size
python upload.py --entity works --input ../works/ --batch-size 1000
Supported entities
works, authors, sources, institutions, topics, domains, fields, subfields, sdgs, countries, continents, languages, keywords, publishers, funders, awards, concepts, work-types, source-types, institution-types, licenses
Mappings & Transforms
mappings.py defines ES mappings derived from the OpenAPI spec with these query optimizations:
| Feature | Applies to |
|---|---|
search_as_you_type on title |
works |
completion suggester on display_name |
works, authors, sources, institutions, topics, keywords, publishers, funders |
rank_feature on cited_by_count |
works, authors |
geo_point on geo.location |
institutions |
text field for reconstructed abstract |
works |
Ingestion transforms (applied automatically during upload):
- works — reconstructs
abstractfromabstract_inverted_index - works, authors — copies
cited_by_counttocited_by_count_rank - institutions — synthesizes
geo.locationas{lat, lon}fromgeo.latitude/geo.longitude
Languages
Python
100%