getting-started.asciidoc 2.2 KB

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