A complete news monitoring and analytics system using newsdata.io API and serverless Elasticsearch with Kibana dashboards.
- Fetch news articles from newsdata.io API
- Index articles into Elasticsearch
- Sentiment analysis on news content
- Kibana dashboards for visualization
- Deduplication to avoid indexing duplicate articles
- Error handling and logging
- Configurable topics and categories
- Python 3.8+
- Serverless Elasticsearch instance (Elastic Cloud)
- newsdata.io API key
- Kibana access (comes with Elastic Cloud)
cd news-elasticsearch-pipelinepip install -r requirements.txtCopy the example environment file and fill in your credentials:
cp .env.example .envEdit .env file with your credentials:
# newsdata.io API
NEWSDATA_API_KEY=your_newsdata_api_key_here
# Elasticsearch Configuration
ELASTIC_CLOUD_ID=your_cloud_id_here
ELASTIC_API_KEY=your_api_key_here
# Or use endpoint + credentials
ELASTIC_ENDPOINT=https://your-deployment.es.us-central1.gcp.cloud.es.io
ELASTIC_USERNAME=elastic
ELASTIC_PASSWORD=your_password_here
# Application Settings
INDEX_NAME=news-articles
LOG_LEVEL=INFOThis creates the Elasticsearch index with proper mapping:
python scripts/setup_index.pypython scripts/fetch_news.py- Log into your Elastic Cloud Kibana instance
- Go to Management β Stack Management β Kibana β Saved Objects
- Import the dashboard:
kibana/news_dashboard.ndjson - View your dashboard under Analytics β Dashboard
news-elasticsearch-pipeline/
βββ config/
β βββ __init__.py
β βββ settings.py # Configuration management
β βββ elasticsearch.py # ES connection setup
βββ src/
β βββ __init__.py
β βββ news_fetcher.py # newsdata.io API client
β βββ indexer.py # Elasticsearch indexing logic
β βββ sentiment.py # Sentiment analysis
β βββ utils.py # Helper functions
βββ scripts/
β βββ setup_index.py # Create ES index
β βββ fetch_news.py # Main script to fetch and index
β βββ delete_index.py # Utility to delete index
βββ kibana/
β βββ news_dashboard.ndjson # Pre-built Kibana dashboard
βββ tests/
β βββ __init__.py
β βββ test_news_fetcher.py
β βββ test_indexer.py
βββ logs/ # Application logs (auto-created)
βββ .env.example # Environment variables template
βββ .gitignore
βββ requirements.txt
βββ README.md
Edit config/settings.py to customize what news to fetch:
SEARCH_QUERIES = [
'artificial intelligence',
'machine learning',
'cryptocurrency',
'climate change'
]
CATEGORIES = ['technology', 'business', 'science', 'politics']
COUNTRIES = ['us', 'gb', 'in']
LANGUAGES = ['en']The included dashboard provides:
- Article Timeline: Publications over time
- Category Distribution: Pie chart of news categories
- Sentiment Analysis: Positive/Negative/Neutral breakdown
- Top Sources: Most active news sources
- Trending Keywords: Word cloud of popular terms
- Recent Articles: Table of latest indexed news
# Edit crontab
crontab -e
# Add this line to run every 6 hours
0 */6 * * * cd /path/to/news-elasticsearch-pipeline && /usr/bin/python3 scripts/fetch_news.py >> logs/cron.log 2>&1- Open Task Scheduler
- Create Basic Task
- Set trigger (daily, hourly, etc.)
- Action: Start a program
- Program:
python - Arguments:
scripts/fetch_news.py - Start in:
C:\path\to\news-elasticsearch-pipeline
Run tests:
pytest tests/from src.news_fetcher import NewsFetcher
fetcher = NewsFetcher()
articles = fetcher.fetch_news(query='bitcoin', country='us')
print(f"Found {len(articles)} articles")from src.indexer import NewsIndexer
indexer = NewsIndexer()
indexer.index_articles(articles)from src.sentiment import analyze_sentiment
text = "This is great news for the technology sector!"
sentiment = analyze_sentiment(text)
print(sentiment) # 'positive'If you get connection errors:
- Verify your Elasticsearch credentials in
.env - Check if your IP is whitelisted in Elastic Cloud
- Ensure your Elastic deployment is running
newsdata.io free tier limits:
- 200 requests per day
- Implement caching or reduce fetch frequency
# Delete and recreate index
python scripts/delete_index.py
python scripts/setup_index.py- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
This project is for educational purposes. Make sure to comply with:
- newsdata.io Terms of Service
- Elasticsearch Cloud usage policies
- News source copyright and attribution requirements
- newsdata.io for news API
- Elastic for Elasticsearch and Kibana
- Community contributors
For questions or support, please open an issue on GitHub.
Happy News Monitoring! π°β¨

