Yes, it is absolutely possible — and often advisable — to index large amounts of log data using a search engine like Solr, Elasticsearch, or specialized tools built on top of them (e.g., ELK Stack, OpenSearch, or Graylog) instead of using grep, which becomes inefficient at scale.
🔍 Recommended Tools for Log Search
Here are some commonly used applications specifically for managing and searching log files:
✅ 1. Elasticsearch (part of the ELK / Elastic Stack)
- Log shipping + storage + querying
- Often used with:
- Logstash (for parsing and forwarding logs)
- Filebeat (lightweight log shipper)
- Kibana (front-end UI)
- Pros: Built for time-series data, real-time querying, structured document storage.
- Cons: Can become resource-intensive at scale.
✅ 2. Apache Solr
- Solr can indeed index log files as long as you parse and standardize the input.
- Has full-text search capabilities, faceting, and is suitable if you're already using Solr elsewhere.
- Requires a custom parser or data loader.
✅ 3. OpenSearch
- Open-source fork of Elasticsearch by Amazon.
- Very similar setup/use of ingestion pipelines and dashboards.
- Works with Filebeat/Fluent Bit/Logstash similarly.
✅ 4. Graylog or Loki
- Focused on log aggregation and analysis.
- Graylog: Log ingestion + dashboarding.
- Grafana Loki: Optimized for logs, pairs well with Prometheus.
If your primary need is full-text and structured search through log files, Elasticsearch or Solr are the most suitable.
⚙️ How to Feed NGINX Logs into Solr
To ingest log files into Solr, you need to parse the logs, possibly convert them to JSON or XML, and post them to Solr. Here's a high-level approach:
Option A: Parse Logs and Index Them into Solr
1. Prepare Solr
-
Install Solr (if not already):
brew install solr # For macOS
sudo apt install solr # For Ubuntu
-
Start Solr:
solr start
-
Create a collection/core:
solr create -c nginxlogs
2. Parse Log Files
Your logs likely follow the default NGINX log format. Example:
127.0.0.1 - - [07/May/2025:10:45:06 +0000] "GET /index.html HTTP/1.1" 200 1024 "-" "Mozilla/5.0"
You can use Python or another script to parse and convert it to a structured format like JSON:
import re
import json
log_pattern = re.compile(
r'(?P<ip>\S+) \S+ \S+ \[(?P<timestamp>[^\]]+)\] '
r'"(?P<method>\S+) (?P<path>\S+) \S+" (?P<status>\d+) (?P<size>\d+) "[^"]*" "(?P<agent>[^"]+)"'
)
def parse_line(line):
match = log_pattern.match(line)
if match:
return match.groupdict()
return None
with open('/var/log/nginx/access.log') as f:
with open('parsed_logs.json', 'w') as out:
for line in f:
entry = parse_line(line)
if entry:
json.dump(entry, out)
out.write('\n')
3. Post JSON Data to Solr
Use Solr’s JSON update handler to post logs:
curl http://localhost:8983/solr/nginxlogs/update?commit=true \
-H 'Content-Type: application/json' \
--data-binary @parsed_logs.json
Or use Solr's post.jar:
java -Dtype=application/json -jar /path/to/solr/example/exampledocs/post.jar parsed_logs.json
Make sure your collection's schema supports dynamic fields or define the fields (ip, timestamp, etc.) beforehand.
Option B: Use Logstash with Solr Output
Although less common than Elasticsearch, Logstash can output to Solr:
input {
file {
path => "/var/log/nginx/access.log"
start_position => "beginning"
}
}
filter {
grok {
match => { "message" => "%{COMMONAPACHELOG}" }
}
}
output {
solr_http {
solr_url => "http://localhost:8983/solr/nginxlogs"
}
}
Note: You will need the logstash-output-solr_http plugin.
🆚 Solr vs Elasticsearch for Logs
| Feature | Elasticsearch | Solr |
|---|
| Time-series support | ✅ Built-in | 🚫 Not native |
| Ecosystem | ✅ (Logstash, Kibana, Beats) | Smaller |
| Query experience | Powerful DSL | Standard Lucene queries |
| Real-time ingestion | ✅ | ✅ (with tuning) |
| Schemaless mode | ✅ | ✅ |
Unless you're already invested in Solr, Elasticsearch or OpenSearch might be easier to set up for logs.
✅ Recommendation
If you just want to search beyond grep and have lots of logs:
- Quick & Simple:
- Use Elasticsearch + Filebeat.
- Already using Solr?
- Write a small script to transform + upload logs to Solr.
- UI/Dashboarding Needs?
- Use Kibana with Elasticsearch.
- Or Graylog / Loki.
Do you want a working example based on either Elasticsearch or Solr, with docker setup?