translate.asciidoc 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. }
  46. --------------------------------------------------
  47. Which is the request that SQL will run to provide the results.
  48. In this case, SQL will use the <<scroll-search-results,scroll>>
  49. API. If the result contained an aggregation then SQL would use
  50. the normal <<search-request-body,search>> API.
  51. The request body accepts the same <<sql-search-api-request-body,parameters>> as
  52. the <<sql-search-api,SQL search API>>, excluding `cursor`.