ElasticSearch-无法解析要映射的内容-意外字符('\“'

时间:2019-01-23 22:57:00

标签: elasticsearch jdbc

想知道您能否提供帮助,我在Elasticsearch中的代码出现问题,并给出了错误。我的代码在下面,输出也在下面,非常感谢您的帮助。

curl -X PUT "localhost:9200/_mapping/jdbc" -H 'Content-Type: application/x-ndjson' -d '
{
"mappings": {
"jdbc" : { 
"properties" : {
"mac_client" : {
"type" : "string",
"index": "not_analyzed"
}
"mac_sniffer" : {
"type" : "string"
"index": "not_analyzed"
}
"rssi" : {
"type" : "long"
}
"timestamp" : {
"type" : "date"
"format" : "strict_date_optional_time||epoch_millis"
}
}
}
}
}
'

我遇到错误

    {"error":{"root_cause":[{"type":"parse_exception","reason":"Failed to parse content to map"}],"type":"parse_exception","reason":"Failed to parse content to map","caused_by":{"type":"json_parse_exception","reason":"Unexpected character ('\"' (code 34)): was expecting comma to separate OBJECT entries\n at [Source: org.elasticsearch.common.compress.deflate.DeflateCompressor$1@66d3b7cb; line: 10, column: 12]"}},"status":400}

2 个答案:

答案 0 :(得分:3)

您的json无效,以后可以使用https://jsonformatter.curiousconcept.com/之类的东西来进行检查。

以下内容应有效-格式正确的json总是有助于查看错误

{
  "mappings": {
    "jdbc": {
      "properties": {
        "mac_client": {
          "type": "string",
          "index": "not_analyzed"
        },
        "mac_sniffer": {
          "type": "string",
          "index": "not_analyzed"
        },
        "rssi": {
          "type": "long"
        },
        "timestamp": {
          "type": "date",
          "format": "strict_date_optional_time||epoch_millis"
        }
      }
    }
  }
}

答案 1 :(得分:1)

您在JSON对象中缺少逗号。

curl -X PUT "localhost:9200/_mapping/jdbc" -H 'Content-Type: application/x-ndjson' -d '
{
"mappings": {
"jdbc" : { 
"properties" : {
"mac_client" : {
"type" : "string",
"index": "not_analyzed"
}, // <==== comma missing
"mac_sniffer" : {
"type" : "string"
"index": "not_analyzed"
}, // <==== comma missing
"rssi" : {
"type" : "long"
}, // <==== comma missing
"timestamp" : {
"type" : "date"
"format" : "strict_date_optional_time||epoch_millis"
}
}
}
}
}
'