translate.asciidoc 1.4 KB

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