translate.asciidoc 1.3 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,console]
  8. --------------------------------------------------
  9. POST /_sql/translate
  10. {
  11. "query": "SELECT * FROM library ORDER BY page_count DESC",
  12. "fetch_size": 10
  13. }
  14. --------------------------------------------------
  15. // TEST[setup:library]
  16. Which returns:
  17. [source,console-result]
  18. --------------------------------------------------
  19. {
  20. "size": 10,
  21. "_source": false,
  22. "fields": [
  23. {
  24. "field": "author"
  25. },
  26. {
  27. "field": "name"
  28. },
  29. {
  30. "field": "page_count"
  31. },
  32. {
  33. "field": "release_date",
  34. "format": "strict_date_optional_time_nanos"
  35. }
  36. ],
  37. "sort": [
  38. {
  39. "page_count": {
  40. "order": "desc",
  41. "missing": "_first",
  42. "unmapped_type": "short"
  43. }
  44. }
  45. ]
  46. }
  47. --------------------------------------------------
  48. Which is the request that SQL will run to provide the results.
  49. In this case, SQL will use the <<scroll-search-results,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 the same <<sql-search-api-request-body,parameters>> as
  53. the <<sql-search-api,SQL search API>>, excluding `cursor`.