getting-started.asciidoc 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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,console]
  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. And now you can execute SQL using the <<sql-rest>> right away:
  18. [source,console]
  19. --------------------------------------------------
  20. POST /_sql?format=txt
  21. {
  22. "query": "SELECT * FROM library WHERE release_date < '2000-01-01'"
  23. }
  24. --------------------------------------------------
  25. // TEST[continued]
  26. Which should return something along the lines of:
  27. [source,text]
  28. --------------------------------------------------
  29. author | name | page_count | release_date
  30. ---------------+---------------+---------------+------------------------
  31. Dan Simmons |Hyperion |482 |1989-05-26T00:00:00.000Z
  32. Frank Herbert |Dune |604 |1965-06-01T00:00:00.000Z
  33. --------------------------------------------------
  34. // TESTRESPONSE[s/\|/\\|/ s/\+/\\+/]
  35. // TESTRESPONSE[non_json]
  36. You can also use the <<sql-cli>>. There is a script to start it
  37. shipped in x-pack's bin directory:
  38. [source,bash]
  39. --------------------------------------------------
  40. $ ./bin/elasticsearch-sql-cli
  41. --------------------------------------------------
  42. From there you can run the same query:
  43. [source,sqlcli]
  44. --------------------------------------------------
  45. sql> SELECT * FROM library WHERE release_date < '2000-01-01';
  46. author | name | page_count | release_date
  47. ---------------+---------------+---------------+------------------------
  48. Dan Simmons |Hyperion |482 |1989-05-26T00:00:00.000Z
  49. Frank Herbert |Dune |604 |1965-06-01T00:00:00.000Z
  50. --------------------------------------------------