translate.asciidoc 1.4 KB

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