ElasticSearch - Failed to parse content to map - Unexpected character ('\"'

Refresh

April 2019

Views

140 time

1

Wondering if you can help, I'm having issues with my code in Elasticsearch that is giving out an error. My code is below and the output is also below, any help is greatly appreciated.

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 I am getting

    {"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: [email protected]d3b7cb; line: 10, column: 12]"}},"status":400}

2 answers

1

You missing commas inside your JSON object.

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"
}
}
}
}
}
'
3

Your json is not valid you can use something like https://jsonformatter.curiousconcept.com/ to check in the future.

Following should be valid - well formatted json always helps see errors

{
  "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"
        }
      }
    }
  }
}