translate.asciidoc 1.5 KB

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