cli.asciidoc 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. [role="xpack"]
  2. [testenv="basic"]
  3. [[sql-cli]]
  4. == SQL CLI
  5. Elasticsearch ships with a script to run the SQL CLI in its `bin` directory:
  6. [source,bash]
  7. --------------------------------------------------
  8. $ ./bin/elasticsearch-sql-cli
  9. --------------------------------------------------
  10. You can pass the URL of the Elasticsearch instance to connect to as
  11. the first parameter:
  12. [source,bash]
  13. --------------------------------------------------
  14. $ ./bin/elasticsearch-sql-cli https://some.server:9200
  15. --------------------------------------------------
  16. If security is enabled on your cluster, you can pass the username
  17. and password in the form `username:password@host_name:port`
  18. to the SQL CLI:
  19. [source,bash]
  20. --------------------------------------------------
  21. $ ./bin/elasticsearch-sql-cli https://sql_user:strongpassword@some.server:9200
  22. --------------------------------------------------
  23. Once the CLI is running you can use any <<sql-spec,query>> that
  24. Elasticsearch supports:
  25. [source,sqlcli]
  26. --------------------------------------------------
  27. sql> SELECT * FROM library WHERE page_count > 500 ORDER BY page_count DESC;
  28. author | name | page_count | release_date
  29. -----------------+--------------------+---------------+---------------
  30. Peter F. Hamilton|Pandora's Star |768 |1078185600000
  31. Vernor Vinge |A Fire Upon the Deep|613 |707356800000
  32. Frank Herbert |Dune |604 |-144720000000
  33. Alastair Reynolds|Revelation Space |585 |953078400000
  34. James S.A. Corey |Leviathan Wakes |561 |1306972800000
  35. --------------------------------------------------
  36. // TODO it'd be lovely to be able to assert that this is correct but
  37. // that is probably more work then it is worth right now.
  38. The jar containing the SQL CLI is a stand alone Java application and
  39. the scripts just launch it. You can move it around to other machines
  40. without having to install Elasticsearch on them. Without the already
  41. provided script files, you can use a command similar to the following
  42. to start the SQL CLI:
  43. [source,bash]
  44. --------------------------------------------------
  45. $ ./java -jar [PATH_TO_CLI_JAR]/elasticsearch-sql-cli-[VERSION].jar https://some.server:9200
  46. --------------------------------------------------
  47. or
  48. [source,bash]
  49. --------------------------------------------------
  50. $ ./java -cp [PATH_TO_CLI_JAR]/elasticsearch-sql-cli-[VERSION].jar org.elasticsearch.xpack.sql.cli.Cli https://some.server:9200
  51. --------------------------------------------------
  52. The jar name will be different for each Elasticsearch version (for example `elasticsearch-sql-cli-7.3.2.jar`),
  53. thus the generic `VERSION` specified in the example above. Furthermore,
  54. if not running the command from the folder where the SQL CLI jar resides,
  55. you'd have to provide the full path, as well.