2016-01-04 28 views
1

我使用Powershell(通過Cmder)和curl(GoW)在elasticsearch中創建索引模板。創建索引模板時JSON解析異常

這裏是我的捲髮:

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: [[email protected]; line: 3, column: 25]" 
    } 
    }, 
    "status": 400 
} 

ES是說明一個json_parse_exception,但是,我想不出在我的JSON包是無效的。

我的JSON有什麼問題,或者我做了其他不正確的事情?

+0

這很奇怪,我可以在ES 1.x和ES 2.x集羣上執行精確的curl命令(在用'localhost'替換'myAddress'後),沒有任何問題(在MacOS上)。 – Val

+0

@Val,我應該更清楚地注意到我在windows上。看起來答案是我需要的「」「vs」。儘管感謝你的時間。非常感激。 –

+0

沒有問題,我會留下我對Mac問題的意見,登陸這個問題;) – Val

回答

2

原來在窗戶上捲曲需要「」而不是「」。

發現從這個問題的答案: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"""} 
     } 
    } 
} 
' 

看起來可怕,但它的工作。

+0

對這個問題的評論之一提到\「,這對我來說很好,看起來更好。 – LogicalKip