cli.asciidoc 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. [role="xpack"]
  2. [[sql-cli]]
  3. == SQL CLI
  4. Elasticsearch ships with a script to run the SQL CLI in its `bin` directory:
  5. [source,bash]
  6. --------------------------------------------------
  7. $ ./bin/elasticsearch-sql-cli
  8. --------------------------------------------------
  9. You can pass the URL of the Elasticsearch instance to connect to as
  10. the first parameter:
  11. [source,bash]
  12. --------------------------------------------------
  13. $ ./bin/elasticsearch-sql-cli https://some.server:9200
  14. --------------------------------------------------
  15. If security is enabled on your cluster, you can pass the username
  16. and password in the form `username:password@host_name:port`
  17. to the SQL CLI:
  18. [source,bash]
  19. --------------------------------------------------
  20. $ ./bin/elasticsearch-sql-cli https://sql_user:strongpassword@some.server:9200
  21. --------------------------------------------------
  22. Once the CLI is running you can use any <<sql-spec,query>> that
  23. Elasticsearch supports:
  24. [source,sqlcli]
  25. --------------------------------------------------
  26. sql> SELECT * FROM library WHERE page_count > 500 ORDER BY page_count DESC;
  27. author | name | page_count | release_date
  28. -----------------+--------------------+---------------+---------------
  29. Peter F. Hamilton|Pandora's Star |768 |1078185600000
  30. Vernor Vinge |A Fire Upon the Deep|613 |707356800000
  31. Frank Herbert |Dune |604 |-144720000000
  32. Alastair Reynolds|Revelation Space |585 |953078400000
  33. James S.A. Corey |Leviathan Wakes |561 |1306972800000
  34. --------------------------------------------------
  35. // TODO it'd be lovely to be able to assert that this is correct but
  36. // that is probably more work then it is worth right now.
  37. The jar containing the SQL CLI is a stand alone Java application and
  38. the scripts just launch it. You can move it around to other machines
  39. without having to install Elasticsearch on them. Without the already
  40. provided script files, you can use a command similar to the following
  41. to start the SQL CLI:
  42. [source,bash]
  43. --------------------------------------------------
  44. $ ./java -jar [PATH_TO_CLI_JAR]/elasticsearch-sql-cli-[VERSION].jar https://some.server:9200
  45. --------------------------------------------------
  46. or
  47. [source,bash]
  48. --------------------------------------------------
  49. $ ./java -cp [PATH_TO_CLI_JAR]/elasticsearch-sql-cli-[VERSION].jar org.elasticsearch.xpack.sql.cli.Cli https://some.server:9200
  50. --------------------------------------------------
  51. The jar name will be different for each Elasticsearch version (for example `elasticsearch-sql-cli-7.3.2.jar`),
  52. thus the generic `VERSION` specified in the example above. Furthermore,
  53. if not running the command from the folder where the SQL CLI jar resides,
  54. you'd have to provide the full path, as well.
  55. [[cli-commands]]
  56. [discrete]
  57. === CLI commands
  58. Apart from SQL queries, CLI can also execute some specific commands:
  59. `allow_partial_search_results = <boolean>` (default `false`)::
  60. If `true`, returns partial results if there are shard request timeouts or
  61. <<shard-failures,shard failures>>. If `false`, returns an error with
  62. no partial results.
  63. [source,sqlcli]
  64. --------------------------------------------------
  65. sql> allow_partial_search_results = true;
  66. allow_partial_search_results set to true
  67. --------------------------------------------------
  68. `fetch_size = <number>` (default `1000`)::
  69. Allows to change the size of fetches for query execution.
  70. Each fetch is delimited by fetch separator (if explicitly set).
  71. [source,sqlcli]
  72. --------------------------------------------------
  73. sql> fetch_size = 2000;
  74. fetch size set to 2000
  75. --------------------------------------------------
  76. `fetch_separator = <string>` (empty string by default)::
  77. Allows to change the separator string between fetches.
  78. [source,sqlcli]
  79. --------------------------------------------------
  80. sql> fetch_separator = "---------------------";
  81. fetch separator set to "---------------------"
  82. --------------------------------------------------
  83. `lenient = <boolean>` (default `false`)::
  84. If `false`, {es-sql} returns an error for fields containing <<array,array values>>.
  85. If `true`, {es-sql} returns the first value from the array with no guarantee of consistent results.
  86. [source,sqlcli]
  87. --------------------------------------------------
  88. sql> lenient = true;
  89. lenient set to true
  90. --------------------------------------------------
  91. `info`::
  92. Returns server information.
  93. [source,sqlcli]
  94. --------------------------------------------------
  95. sql> info;
  96. Node:mynode Cluster:elasticsearch Version:8.3
  97. --------------------------------------------------
  98. `exit`::
  99. Closes the CLI.
  100. [source,sqlcli]
  101. --------------------------------------------------
  102. sql> exit;
  103. Bye!
  104. --------------------------------------------------
  105. `cls`::
  106. Clears the screen.
  107. [source,sqlcli]
  108. --------------------------------------------------
  109. sql> cls;
  110. --------------------------------------------------
  111. `logo`::
  112. Prints Elastic logo.
  113. [source,sqlcli]
  114. --------------------------------------------------
  115. sql> logo;
  116. asticElasticE
  117. ElasticE sticEla
  118. sticEl ticEl Elast
  119. lasti Elasti tic
  120. cEl ast icE
  121. icE as cEl
  122. icE as cEl
  123. icEla las El
  124. sticElasticElast icElas
  125. las last ticElast
  126. El asti asti stic
  127. El asticEla Elas icE
  128. El Elas cElasticE ticEl cE
  129. Ela ticEl ticElasti cE
  130. las astic last icE
  131. sticElas asti stic
  132. icEl sticElasticElast
  133. icE sticE ticEla
  134. icE sti cEla
  135. icEl sti Ela
  136. cEl sti cEl
  137. Ela astic ticE
  138. asti ElasticElasti
  139. ticElasti lasticElas
  140. ElasticElast
  141. SQL
  142. 8.3.0
  143. --------------------------------------------------