translate.asciidoc 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. [role="xpack"]
  2. [testenv="basic"]
  3. [[sql-translate]]
  4. == SQL Translate API
  5. beta[]
  6. The SQL Translate API accepts SQL in a JSON document and translates it
  7. into native Elasticsearch queries. For example:
  8. [source,js]
  9. --------------------------------------------------
  10. POST /_sql/translate
  11. {
  12. "query": "SELECT * FROM library ORDER BY page_count DESC",
  13. "fetch_size": 10
  14. }
  15. --------------------------------------------------
  16. // CONSOLE
  17. // TEST[setup:library]
  18. Which returns:
  19. [source,js]
  20. --------------------------------------------------
  21. {
  22. "size" : 10,
  23. "docvalue_fields" : [
  24. {
  25. "field": "page_count"
  26. },
  27. {
  28. "field": "release_date",
  29. "format": "epoch_millis"
  30. }
  31. ],
  32. "_source": {
  33. "includes": [
  34. "author",
  35. "name"
  36. ],
  37. "excludes": []
  38. },
  39. "sort" : [
  40. {
  41. "page_count" : {
  42. "order" : "desc",
  43. "missing" : "_first",
  44. "unmapped_type" : "short"
  45. }
  46. }
  47. ]
  48. }
  49. --------------------------------------------------
  50. // TESTRESPONSE
  51. Which is the request that SQL will run to provide the results.
  52. In this case, SQL will use the <<search-request-scroll,scroll>>
  53. API. If the result contained an aggregation then SQL would use
  54. the normal <<search-request-body,search>> API.
  55. The request body accepts all of the <<sql-rest-fields,fields>> that
  56. the <<sql-rest,SQL REST API>> accepts except `cursor`.