Skip to main content

OpenSearch Overview

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.

Basic Syntax

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}}}"

Connection Configuration

OPENSEARCH_CONFIG Parameters

BASE_URL
string
required
OpenSearch endpoint URL including port (e.g., https://opensearch.example.com:9200).
USERNAME
string
required
OpenSearch username.
PASSWORD
string
required
OpenSearch password.
USE_SSL
boolean
Enable HTTPS. Default: false.
IGNORE_CERT_ERRORS
boolean
Ignore certificate validation errors. Default: false.

CLEAN Query Format

OpenSearch routes use the CLEAN format for document indexing:
WITH QUERY "CLEAN:{index: <index_name>, body: {<field>: <value>, ...}}"

CLEAN Placeholders

PlaceholderDescription
{value.json}Full JSON payload as embedded object
{value.json.field}Specific field from JSON payload
{timestamp}Message timestamp (use @timestamp for Kibana)
{source_topic}Original MQTT topic
{field}Field extracted from topic path

Complete Examples

Index sensor data for search:
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}}}"

Index Mapping Example

Create an index with explicit mappings for better search and aggregation:
PUT /sensor-data
{
  "mappings": {
    "properties": {
      "@timestamp": { "type": "date" },
      "sensor_id": { "type": "keyword" },
      "data": {
        "properties": {
          "temperature": { "type": "float" },
          "humidity": { "type": "float" }
        }
      }
    }
  }
}

Troubleshooting

  • Verify BASE_URL is correct including port
  • Check OpenSearch is running and accessible
  • Verify firewall allows connections on port 9200
  • Verify USERNAME and PASSWORD are correct
  • Check user has permissions to index documents
  • Ensure USE_SSL matches the endpoint (http vs https)
  • For self-signed certs, set IGNORE_CERT_ERRORS “true”
  • Verify certificate chain is complete
  • Verify index name is valid (lowercase, no special chars)
  • Check field mappings don’t conflict
  • Review OpenSearch logs for detailed errors

Next Steps