translate.asciidoc 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. [role="xpack"]
  2. [testenv="basic"]
  3. [[sql-translate]]
  4. == SQL Translate API
  5. beta[]
  6. The SQL Translate API accepts SQL in a JSON document and translates it
  7. into native Elasticsearch queries. For example:
  8. [source,js]
  9. --------------------------------------------------
  10. POST /_sql/translate
  11. {
  12. "query": "SELECT * FROM library ORDER BY page_count DESC",
  13. "fetch_size": 10
  14. }
  15. --------------------------------------------------
  16. // CONSOLE
  17. // TEST[setup:library]
  18. Which returns:
  19. [source,js]
  20. --------------------------------------------------
  21. {
  22. "size" : 10,
  23. "docvalue_fields" : [
  24. {
  25. "field": "page_count",
  26. "format": "use_field_mapping"
  27. },
  28. {
  29. "field": "release_date",
  30. "format": "epoch_millis"
  31. }
  32. ],
  33. "_source": {
  34. "includes": [
  35. "author",
  36. "name"
  37. ],
  38. "excludes": []
  39. },
  40. "sort" : [
  41. {
  42. "page_count" : {
  43. "order" : "desc",
  44. "missing" : "_first",
  45. "unmapped_type" : "short"
  46. }
  47. }
  48. ]
  49. }
  50. --------------------------------------------------
  51. // TESTRESPONSE
  52. Which is the request that SQL will run to provide the results.
  53. In this case, SQL will use the <<search-request-scroll,scroll>>
  54. API. If the result contained an aggregation then SQL would use
  55. the normal <<search-request-body,search>> API.
  56. The request body accepts all of the <<sql-rest-fields,fields>> that
  57. the <<sql-rest,SQL REST API>> accepts except `cursor`.