lookup.asciidoc 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. [discrete]
  2. [[esql-lookup]]
  3. === `LOOKUP`
  4. experimental::["LOOKUP is a highly experimental and only available in SNAPSHOT versions."]
  5. `LOOKUP` matches values from the input against a `table` provided in the request,
  6. adding the other fields from the `table` to the output.
  7. **Syntax**
  8. [source,esql]
  9. ----
  10. LOOKUP table ON match_field1[, match_field2, ...]
  11. ----
  12. *Parameters*
  13. `table`::
  14. The name of the `table` provided in the request to match.
  15. `match_field`::
  16. The fields in the input to match against the table.
  17. *Examples*
  18. // tag::examples[]
  19. [source,console,id=esql-lookup-example]
  20. ----
  21. POST /_query?format=txt
  22. {
  23. "query": """
  24. FROM library
  25. | SORT page_count DESC
  26. | KEEP name, author
  27. | LOOKUP era ON author
  28. | LIMIT 5
  29. """,
  30. "tables": {
  31. "era": {
  32. "author": {"keyword": ["Frank Herbert", "Peter F. Hamilton", "Vernor Vinge", "Alastair Reynolds", "James S.A. Corey"]},
  33. "era": {"keyword": [ "The New Wave", "Diamond", "Diamond", "Diamond", "Hadron"]}
  34. }
  35. }
  36. }
  37. ----
  38. // TEST[setup:library]
  39. Which returns:
  40. [source,text]
  41. ----
  42. name | author | era
  43. --------------------+-----------------+---------------
  44. Pandora's Star |Peter F. Hamilton|Diamond
  45. A Fire Upon the Deep|Vernor Vinge |Diamond
  46. Dune |Frank Herbert |The New Wave
  47. Revelation Space |Alastair Reynolds|Diamond
  48. Leviathan Wakes |James S.A. Corey |Hadron
  49. ----
  50. // TESTRESPONSE[s/\|/\\|/ s/\+/\\+/]
  51. // TESTRESPONSE[non_json]
  52. // end::examples[]