lookup.asciidoc 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. If the table's column names conflict with existing columns, the existing columns will be dropped.
  16. `match_field`::
  17. The fields in the input to match against the table.
  18. *Examples*
  19. // tag::examples[]
  20. [source,console,id=esql-lookup-example]
  21. ----
  22. POST /_query?format=txt
  23. {
  24. "query": """
  25. FROM library
  26. | SORT page_count DESC
  27. | KEEP name, author
  28. | LOOKUP era ON author
  29. | LIMIT 5
  30. """,
  31. "tables": {
  32. "era": {
  33. "author": {"keyword": ["Frank Herbert", "Peter F. Hamilton", "Vernor Vinge", "Alastair Reynolds", "James S.A. Corey"]},
  34. "era": {"keyword": [ "The New Wave", "Diamond", "Diamond", "Diamond", "Hadron"]}
  35. }
  36. }
  37. }
  38. ----
  39. // TEST[setup:library]
  40. Which returns:
  41. [source,text]
  42. ----
  43. name | author | era
  44. --------------------+-----------------+---------------
  45. Pandora's Star |Peter F. Hamilton|Diamond
  46. A Fire Upon the Deep|Vernor Vinge |Diamond
  47. Dune |Frank Herbert |The New Wave
  48. Revelation Space |Alastair Reynolds|Diamond
  49. Leviathan Wakes |James S.A. Corey |Hadron
  50. ----
  51. // TESTRESPONSE[s/\|/\\|/ s/\+/\\+/]
  52. // TESTRESPONSE[non_json]
  53. // end::examples[]