translate.asciidoc 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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": "page_count"
  25. },
  26. {
  27. "field": "release_date",
  28. "format": "epoch_millis"
  29. }
  30. ],
  31. "_source": {
  32. "includes": [
  33. "author",
  34. "name"
  35. ],
  36. "excludes": []
  37. },
  38. "sort" : [
  39. {
  40. "page_count" : {
  41. "order" : "desc",
  42. "missing" : "_first",
  43. "unmapped_type" : "short"
  44. }
  45. }
  46. ]
  47. }
  48. --------------------------------------------------
  49. // TESTRESPONSE
  50. Which is the request that SQL will run to provide the results.
  51. In this case, SQL will use the <<search-request-scroll,scroll>>
  52. API. If the result contained an aggregation then SQL would use
  53. the normal <<search-request-body,search>> API.
  54. The request body accepts all of the <<sql-rest-fields,fields>> that
  55. the <<sql-rest,SQL REST API>> accepts except `cursor`.