JSON 创建索引模板时解析异常
JSON Parse Exception when creating Index Template
我正在使用 Powershell(通过 Cmder)和 curl
(GoW) 在 elasticsearch 中创建索引模板。
这是我的卷曲:
curl -XPUT http://myAddress:9200/_template/logstash_per_iis -u user:password -d'
{
"template" : "logstash*",
"mappings" : {
"iis" : {
"properties" : {
"response":{"type":"int"},
"site":{"type":"ip"},
"supresponse":{"type":"int"},
"time_taken":{"type":"int"},
"clientHost":{"type":"ip"},
"port":{"type":"int"},
"scstatus":{"type":"int"}
}
}
}
}
'
这是来自 ES 的回复:
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "failed to parse template source"
}
],
"type": "illegal_argument_exception",
"reason": "failed to parse template source",
"caused_by": {
"type": "json_parse_exception",
"reason": "Unrecognized token 'logstash': was expecting ('true', 'false' or 'null')\n at [Source: [B@38a6a400; line: 3, column: 25]"
}
},
"status": 400
}
ES 声明 json_parse_exception
,但是,我不知道我的 JSON 包在哪里无效。
我的 JSON 有什么问题还是我做错了什么?
原来 windows 上的 curl 需要 """ 而不仅仅是 ".
找到这个问题的答案:
所以,我的 curl 最终看起来像这样:..
curl -XPUT http://myAddress:9200/_template/logstash_per_iis -u user:password -d'
{
"""template""" : """logstash*"""
"""mappings""" : {
"""iis""" : {
"""response""":{"""type""":"""int"""},
"""site""":{"""type""":"""ip"""},
"""supresponse""":{"""type""":"""int"""},
"""time_taken""":{"""type""":"""int"""},
"""clientHost""":{"""type""":"""ip"""},
"""port""":{"""type""":"""int"""},
"""scstatus""":{"""type""":"""int"""}
}
}
}
'
看起来很糟糕,但它确实有效。
我正在使用 Powershell(通过 Cmder)和 curl
(GoW) 在 elasticsearch 中创建索引模板。
这是我的卷曲:
curl -XPUT http://myAddress:9200/_template/logstash_per_iis -u user:password -d'
{
"template" : "logstash*",
"mappings" : {
"iis" : {
"properties" : {
"response":{"type":"int"},
"site":{"type":"ip"},
"supresponse":{"type":"int"},
"time_taken":{"type":"int"},
"clientHost":{"type":"ip"},
"port":{"type":"int"},
"scstatus":{"type":"int"}
}
}
}
}
'
这是来自 ES 的回复:
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "failed to parse template source"
}
],
"type": "illegal_argument_exception",
"reason": "failed to parse template source",
"caused_by": {
"type": "json_parse_exception",
"reason": "Unrecognized token 'logstash': was expecting ('true', 'false' or 'null')\n at [Source: [B@38a6a400; line: 3, column: 25]"
}
},
"status": 400
}
ES 声明 json_parse_exception
,但是,我不知道我的 JSON 包在哪里无效。
我的 JSON 有什么问题还是我做错了什么?
原来 windows 上的 curl 需要 """ 而不仅仅是 ".
找到这个问题的答案:
所以,我的 curl 最终看起来像这样:..
curl -XPUT http://myAddress:9200/_template/logstash_per_iis -u user:password -d'
{
"""template""" : """logstash*"""
"""mappings""" : {
"""iis""" : {
"""response""":{"""type""":"""int"""},
"""site""":{"""type""":"""ip"""},
"""supresponse""":{"""type""":"""int"""},
"""time_taken""":{"""type""":"""int"""},
"""clientHost""":{"""type""":"""ip"""},
"""port""":{"""type""":"""int"""},
"""scstatus""":{"""type""":"""int"""}
}
}
}
'
看起来很糟糕,但它确实有效。