The OPENSEARCH route indexes MQTT messages in OpenSearch for full-text search, real-time analytics, and dashboard visualization. It uses the CLEAN query format for simplified document indexing.
OpenSearch is ideal for log aggregation, metrics visualization, and full-text search across IoT data. Connect it to OpenSearch Dashboards for powerful visualizations.
DEFINE ROUTE SensorIndex WITH TYPE OPENSEARCH ADD OPENSEARCH_CONFIG WITH BASE_URL "https://opensearch.example.com:9200" WITH USERNAME "admin" WITH PASSWORD "secure_password" WITH USE_SSL "true" ADD EVENT IndexSensorReading WITH SOURCE_TOPIC "sensors/+/data" WITH QUERY "CLEAN:{index: sensor-data, body: {@timestamp: {timestamp}, sensor: {sensor_id}, reading: {value.json}}}"
DEFINE ROUTE SensorIndex WITH TYPE OPENSEARCH ADD OPENSEARCH_CONFIG WITH BASE_URL "https://opensearch.example.com:9200" WITH USERNAME "admin" WITH PASSWORD "secure_password" WITH USE_SSL "true" ADD EVENT IndexReading WITH SOURCE_TOPIC "sensors/+/data" WITH DESTINATION_TOPIC "search/status" WITH QUERY "CLEAN:{index: sensor-data, body: {@timestamp: {timestamp}, sensor_id: {sensor_id}, data: {value.json}}}"
Aggregate application logs:
Copy
Ask AI
DEFINE ROUTE LogIndex WITH TYPE OPENSEARCH ADD OPENSEARCH_CONFIG WITH BASE_URL "https://opensearch.example.com:9200" WITH USERNAME "admin" WITH PASSWORD "admin_password" WITH USE_SSL "true" ADD EVENT IndexLogs WITH SOURCE_TOPIC "logs/+/+" WITH QUERY "CLEAN:{index: application-logs, body: {@timestamp: {timestamp}, source: {source_topic}, level: {value.json.level}, message: {value.json.message}}}"
Use date-based index names for time-series:
Copy
Ask AI
DEFINE ROUTE TimeSeriesIndex WITH TYPE OPENSEARCH ADD OPENSEARCH_CONFIG WITH BASE_URL "https://opensearch.example.com:9200" WITH USERNAME "admin" WITH PASSWORD "secure_password" WITH USE_SSL "true" ADD EVENT IndexMetrics WITH SOURCE_TOPIC "metrics/#" WITH QUERY "CLEAN:{index: metrics, body: {@timestamp: {timestamp}, topic: {source_topic}, metrics: {value.json}}}"
Configure Index Lifecycle Management (ILM) in OpenSearch for automatic rollover.
Connect with certificate validation disabled:
Copy
Ask AI
DEFINE ROUTE DevIndex WITH TYPE OPENSEARCH ADD OPENSEARCH_CONFIG WITH BASE_URL "https://localhost:9200" WITH USERNAME "admin" WITH PASSWORD "admin" WITH USE_SSL "true" WITH IGNORE_CERT_ERRORS "true" ADD EVENT IndexData WITH SOURCE_TOPIC "data/#" WITH QUERY "CLEAN:{index: dev-data, body: {@timestamp: {timestamp}, topic: {source_topic}, payload: {value.json}}}"
Only use IGNORE_CERT_ERRORS in development environments.