我正在使用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有什么问题,或者我做错了什么?
答案 0 :(得分:2)
关闭Windows上的卷曲需要“”“而不仅仅是”。
从这个问题找到答案:https://stackoverflow.com/a/27761856/899048
所以,我的卷发最终看起来像这样:..
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"""}
}
}
}
'
看起来很可怕,但确实有效。