templates - elasticsearch-索引模板创建错误-解析异常,未知 key

标签 templates elasticsearch exception indexing mapping

我刚刚将集群从6.1.x升级到7.9.x版本。尝试修复索引模板,以便在午夜过后的某个时间推送我的数据时,会自动创建新的每日索引。
这是我的方法:

## create template and mapping
 
PUT http://es1:9200/_template/tmp_staging_devices_1
{
    "template": "staging-devices-*",
    "settings": {
        "number_of_shards": 3
    },
    "mappings": {
        "properties": {
            "ts": {"type": "date", "format": "epoch_millis"},
            "server_ts": {"type": "date", "format": "epoch_millis"},
            "raw": {"type": "binary"}
        }
    }
}
 
## template is listed under the list of templates
 
## trying to put some data into the elasticsearch
PUT http://es1:9200/staging-devices-2020-10-20
{
    "imei": "24779610124313",
    "json": "{\"imei\":\"357796101614313\",\"ts\":1603180834000,\"values\":{\"coreMsgId\":2810,\"obdIt\":{\"distance\":0,\"distanceCombustion\":0,\"idleTime\":0,\"idleTimeCombustion\":0,\"maxSpeed\":0,\"totalEnergyCons\":0,\"totalFuelCons\":0,\"totalTime\":488,\"totalTimeCombustion\":0}}}",
    "raw": "04 00 00 32 0A 18 08 FA 15 32 13 08 00 10 00 18 00 20 00 28 E8 03 30 00 38 00 40 00 48 00 12 0F 33 35 37 37 39 36 31 30 31 36 31 34 33 31 33 18 C2 EE CE D1 CB 2E",
    "server_ts": 1603180834000,
    "ts": 1603180834000
}
 
 
## error that I get back (400 bad request)
{
  "error": {
    "root_cause": [
      {
        "type": "parse_exception",
        "reason": "unknown key [server_ts] for create index"
      }
    ],
    "type": "parse_exception",
    "reason": "unknown key [server_ts] for create index"
  },
  "status": 400
}
我究竟做错了什么?
与“旧系统”的唯一区别是我删除了“值”
{
    "template": "staging-devices*",
    "settings": {
        "number_of_shards": 1
    },
    "mappings": {
        "values": {
            "properties": {
                "ts": {"type": "date", "format": "epoch_millis"},
                "server_ts": {"type": "date", "format": "epoch_millis"},
                "raw": {"type": "binary"}
            }
        }
    }
}

最佳答案

您应该提及type和文档ID。
文档类型_doc是elasticsearch 7.x中的默认类型。
Removal of mapping types
Index some documents
试试这个(通过kibana)-经过测试:

POST staging-devices-2020-10-20/_doc/1
{
    "imei": "24779610124313",
    "json": "{\"imei\":\"357796101614313\",\"ts\":1603180834000,\"values\":{\"coreMsgId\":2810,\"obdIt\":{\"distance\":0,\"distanceCombustion\":0,\"idleTime\":0,\"idleTimeCombustion\":0,\"maxSpeed\":0,\"totalEnergyCons\":0,\"totalFuelCons\":0,\"totalTime\":488,\"totalTimeCombustion\":0}}}",
    "raw": "04 00 00 32 0A 18 08 FA 15 32 13 08 00 10 00 18 00 20 00 28 E8 03 30 00 38 00 40 00 48 00 12 0F 33 35 37 37 39 36 31 30 31 36 31 34 33 31 33 18 C2 EE CE D1 CB 2E",
    "server_ts": 1603180834000,
    "ts": 1603180834000
}
curl :
curl -X PUT "es1:9200/staging-devices-2020-10-20/_doc/1?pretty" -H 'Content-Type: application/json' -d'
{
  "imei": "24779610124313",
  "json": "{\"imei\":\"357796101614313\",\"ts\":1603180834000,\"values\":{\"coreMsgId\":2810,\"obdIt\":{\"distance\":0,\"distanceCombustion\":0,\"idleTime\":0,\"idleTimeCombustion\":0,\"maxSpeed\":0,\"totalEnergyCons\":0,\"totalFuelCons\":0,\"totalTime\":488,\"totalTimeCombustion\":0}}}",
  "raw": "04 00 00 32 0A 18 08 FA 15 32 13 08 00 10 00 18 00 20 00 28 E8 03 30 00 38 00 40 00 48 00 12 0F 33 35 37 37 39 36 31 30 31 36 31 34 33 31 33 18 C2 EE CE D1 CB 2E",
  "server_ts": 1603180834000,
  "ts": 1603180834000
}
'

关于templates - elasticsearch-索引模板创建错误-解析异常,未知 key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64441181/

相关文章:

c++ - 模板虚函数

amazon-web-services - 具有高读取和极低数据的最佳 Elasticsearch 索引分片

Java - 如何处理 OutOfMemoryError?

java - StreamingResponseBody 中的异常处理

ios - 报告 iOS 中特定 Web 服务的应用程序崩溃和异常

c++ - 具有继承性的模板如何显式调用其父级的构造函数?

c++ - "static-if"使用类或函数模板更好?

C++ 模板 NULL 未声明的标识符

json - kibana中文本内部字段的平均值

python - 导出时使用大JSON会导致内存问题