translate.asciidoc 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. [role="xpack"]
  2. [[sql-translate]]
  3. == SQL Translate API
  4. The SQL Translate API accepts SQL in a JSON document and translates it
  5. into native {es} queries. For example:
  6. [source,console]
  7. --------------------------------------------------
  8. POST /_sql/translate
  9. {
  10. "query": "SELECT * FROM library ORDER BY page_count DESC",
  11. "fetch_size": 10
  12. }
  13. --------------------------------------------------
  14. // TEST[setup:library]
  15. Which returns:
  16. [source,console-result]
  17. --------------------------------------------------
  18. {
  19. "size": 10,
  20. "_source": false,
  21. "fields": [
  22. {
  23. "field": "author"
  24. },
  25. {
  26. "field": "name"
  27. },
  28. {
  29. "field": "page_count"
  30. },
  31. {
  32. "field": "release_date",
  33. "format": "strict_date_optional_time_nanos"
  34. }
  35. ],
  36. "sort": [
  37. {
  38. "page_count": {
  39. "order": "desc",
  40. "missing": "_first",
  41. "unmapped_type": "short"
  42. }
  43. }
  44. ],
  45. "track_total_hits": -1
  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-search,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`.