Home > OS >  elasticsearch SQL from Kibana client
elasticsearch SQL from Kibana client

Time:07-19

I am trying to fire a SQL query from the Kibana rest interface.

POST /_sql?format=txt
{
  "query": "select * from table
  where match(description, 'item')"
}

And i get an error saying

{
  "error": {
    "root_cause": [
      {
        "type": "x_content_parse_exception",
        "reason": "[2:12] [sql/query] failed to parse field [query]"
      }
    ],
    "type": "x_content_parse_exception",
    "reason": "[2:12] [sql/query] failed to parse field [query]",
    "caused_by": {
      "type": "json_parse_exception",
      "reason": """Illegal unquoted character ((CTRL-CHAR, code 13)): has to be escaped using backslash to be included in string value
 at [Source: (org.elasticsearch.common.io.stream.ByteBufferStreamInput); line: 2, column: 44]"""
    }
  },
  "status": 400
}

I have tried escaping the single quote but no luck so far.

POST /_sql?format=txt
{
  "query": "select * from table
  where match(description, \"'item'\")"
}

CodePudding user response:

You can try this:

POST /_sql?format=txt
{
  "query": "select * from index_name where match(description , 'item')"
}

Example:

POST idx_example/_bulk
{"index":{}}
{"description": "any name item"}

POST /_sql?format=txt
{
  "query": "select * from idx_example where match(description , 'item')"
}
  • Related