getting-started.asciidoc 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. [role="xpack"]
  2. [testenv="basic"]
  3. [[sql-getting-started]]
  4. == Getting Started with SQL
  5. beta[]
  6. To start using {es-sql}, create
  7. an index with some data to experiment with:
  8. [source,js]
  9. --------------------------------------------------
  10. PUT /library/book/_bulk?refresh
  11. {"index":{"_id": "Leviathan Wakes"}}
  12. {"name": "Leviathan Wakes", "author": "James S.A. Corey", "release_date": "2011-06-02", "page_count": 561}
  13. {"index":{"_id": "Hyperion"}}
  14. {"name": "Hyperion", "author": "Dan Simmons", "release_date": "1989-05-26", "page_count": 482}
  15. {"index":{"_id": "Dune"}}
  16. {"name": "Dune", "author": "Frank Herbert", "release_date": "1965-06-01", "page_count": 604}
  17. --------------------------------------------------
  18. // CONSOLE
  19. And now you can execute SQL using the <<sql-rest>> right away:
  20. [source,js]
  21. --------------------------------------------------
  22. POST /_sql?format=txt
  23. {
  24. "query": "SELECT * FROM library WHERE release_date < '2000-01-01'"
  25. }
  26. --------------------------------------------------
  27. // CONSOLE
  28. // TEST[continued]
  29. Which should return something along the lines of:
  30. [source,text]
  31. --------------------------------------------------
  32. author | name | page_count | release_date
  33. ---------------+---------------+---------------+------------------------
  34. Dan Simmons |Hyperion |482 |1989-05-26T00:00:00.000Z
  35. Frank Herbert |Dune |604 |1965-06-01T00:00:00.000Z
  36. --------------------------------------------------
  37. // TESTRESPONSE[s/\|/\\|/ s/\+/\\+/]
  38. // TESTRESPONSE[_cat]
  39. You can also use the <<sql-cli>>. There is a script to start it
  40. shipped in x-pack's bin directory:
  41. [source,bash]
  42. --------------------------------------------------
  43. $ ./bin/elasticsearch-sql-cli
  44. --------------------------------------------------
  45. From there you can run the same query:
  46. [source,sqlcli]
  47. --------------------------------------------------
  48. sql> SELECT * FROM library WHERE release_date < '2000-01-01';
  49. author | name | page_count | release_date
  50. ---------------+---------------+---------------+------------------------
  51. Dan Simmons |Hyperion |482 |1989-05-26T00:00:00.000Z
  52. Frank Herbert |Dune |604 |1965-06-01T00:00:00.000Z
  53. --------------------------------------------------