Query "-" on fieldname problem

Hi Support,

We have problem querying file name with "-" for example sts-empId. It is complaining - character. Could you please help how to query this?

GET /_sql?format=txt
{

"query":" SELECT sts-empId FROM "sts-amsguled-2020.10.27-000001" LIMIT 300"

}

Error:
{
"error": {
"root_cause": [
{
"type": "x_content_parse_exception",
"reason": "[3:9] [sql/query] failed to parse field [query]"
}
],
"type": "x_content_parse_exception",
"reason": "[3:9] [sql/query] failed to parse field [query]",
"caused_by": {
"type": "json_parse_exception",
"reason": "Unrecognized character escape ''' (code 39)\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@57e3e6ab; line: 3, column: 21]"
}
},
"status": 400
}

The error is saying that you've sent an invalid JSON payload. It sounds like you're sending an escaped single quote \' although this error doesn't match your example request body.

Your example has " embedded within other quotes " which is not valid JSON, you will need to escape the inner quotes:

curl -X POST "localhost:9200/_sql?format=txt" -H 'Content-Type: application/json' -d'
{
  "query":"SELECT sts-empId FROM \"sts-amsguled-2020.10.27-000001\" LIMIT 300"
}
'
1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.