elasticsearch,aws-iot,Amazon Web Services,elasticsearch,Aws Iot" /> elasticsearch,aws-iot,Amazon Web Services,elasticsearch,Aws Iot" />

Amazon web services AWS物联网规则-Elasticsearch的时间戳

Amazon web services AWS物联网规则-Elasticsearch的时间戳,amazon-web-services,elasticsearch,aws-iot,Amazon Web Services,elasticsearch,Aws Iot,拥有一组IoT设备(ESP32),这些设备将JSON对象发布到things/things\u NAME/log,以进行一般调试(将来将扩展到具有值的其他主题) 以下是物联网规则,哪种方式有效 { "sql": "SELECT *, parse_time(\"yyyy-mm-dd'T'hh:mm:ss\", timestamp()) AS timestamp, topic(2) AS deviceId FROM 'things/+/stdout'", "ruleDisabled": fal

拥有一组IoT设备(ESP32),这些设备将JSON对象发布到
things/things\u NAME/log
,以进行一般调试(将来将扩展到具有值的其他主题)

以下是物联网规则,哪种方式有效

{
  "sql": "SELECT *, parse_time(\"yyyy-mm-dd'T'hh:mm:ss\", timestamp()) AS timestamp, topic(2) AS deviceId FROM 'things/+/stdout'",
  "ruleDisabled": false,
  "awsIotSqlVersion": "2016-03-23",
  "actions": [
    {
      "elasticsearch": {
        "roleArn": "arn:aws:iam::xxx:role/iot-es-action-role",
        "endpoint": "https://xxxx.eu-west-1.es.amazonaws.com",
        "index": "devices",
        "type": "device",
        "id": "${newuuid()}"
      }
    }
  ]
}
我不知道如何在Elasticsearch中设置
@timestamp
,以允许基于时间的搜索


也许我在这件事上做错了,但它几乎奏效了

@timestamp
只是一种约定,因为
@
前缀是日志存储生成字段的默认前缀。因为您没有使用Logstash作为IoT和Elasticsearch之间的中间人,所以您没有@timestamp的默认映射

但基本上,它只是一个名称,所以可以随意调用,唯一重要的是在Elasticsearch索引的mappings部分将其声明为时间戳字段

如果出于某种原因,您仍然需要调用
@timestamp
,您可以在
AS
部分中选择带有该前缀的
(可能是物联网sql限制的问题,不确定):

或者在声明映射时使用该功能:

PUT devices/device
{
    "mappings": {
        "properties": {
            "timestamp": {
                "type": "date",
                "copy_to": "@timestamp" 
            },
            "@timestamp": {
                "type": "date",
            }
        }
    }
}

Elasticsearch可以识别与
动态日期格式匹配的日期字符串。
以下格式自动映射为AWS Elasticsearch 7.1中的
日期
字段:

SELECT *, parse_time("yyyy/MM/dd HH:mm:ss", timestamp()) AS timestamp FROM 'events/job/#'
这种方法不需要创建预配置索引,这对于动态创建的索引很重要,例如日志的每日轮换:

devices-${parse_time("yyyy.MM.dd", timestamp(), "UTC")}
根据,

动态日期格式的默认值为:

[“严格日期可选时间”,“yyyy/MM/dd HH:MM:ss Z | | yyyy/MM/dd Z”]


不错,我删除了索引,并用timestamp.type=date重新创建了它,现在一切都正常了。你不能把@放在IoT SQL选择中,不管你用什么引号把它括起来。是的,我想他们可能会禁止某些类型的字符。好吧,至少你在营救时有弹性。祝你好运
devices-${parse_time("yyyy.MM.dd", timestamp(), "UTC")}