@@ -93,19 +93,19 @@ source = employees
9393The query returns the following results:
9494
9595``` text
96- +--------+----------+----+---------------------+
97- | name | reportsTo| id | reportingHierarchy |
98- +--------+----------+----+---------------------+
99- | Dev | Eliot | 1 | [{Eliot, Ron, 2}] |
100- | Eliot | Ron | 2 | [{Ron, Andrew, 3}] |
101- | Ron | Andrew | 3 | [{Andrew, null, 4}] |
102- | Andrew | null | 4 | [] |
103- | Asya | Ron | 5 | [{Ron, Andrew, 3}] |
104- | Dan | Andrew | 6 | [{Andrew, null, 4}] |
105- +--------+----------+----+---------------------+
96+ +--------+----------+----+----------------------------------------------- +
97+ | name | reportsTo| id | reportingHierarchy |
98+ +--------+----------+----+----------------------------------------------- +
99+ | Dev | Eliot | 1 | [{name: Eliot, reportsTo: Ron, id: 2}] |
100+ | Eliot | Ron | 2 | [{name: Ron, reportsTo: Andrew, id: 3}] |
101+ | Ron | Andrew | 3 | [{name: Andrew, reportsTo: null, id: 4}] |
102+ | Andrew | null | 4 | [] |
103+ | Asya | Ron | 5 | [{name: Ron, reportsTo: Andrew, id: 3}] |
104+ | Dan | Andrew | 6 | [{name: Andrew, reportsTo: null, id: 4}] |
105+ +--------+----------+----+----------------------------------------------- +
106106```
107107
108- For Dev, the traversal starts with ` reportsTo="Eliot" ` , finds the Eliot record, and returns it in the ` reportingHierarchy ` array.
108+ Each element in the ` reportingHierarchy ` array is a struct with named fields from the lookup index. For Dev, the traversal starts with ` reportsTo="Eliot" ` , finds the Eliot record, and returns it in the ` reportingHierarchy ` array.
109109
110110## Example 2: Employee Hierarchy with Depth Tracking
111111
@@ -123,19 +123,19 @@ source = employees
123123The query returns the following results:
124124
125125``` text
126- +--------+----------+----+------------------------+
127- | name | reportsTo| id | reportingHierarchy |
128- +--------+----------+----+------------------------+
129- | Dev | Eliot | 1 | [{Eliot, Ron, 2, 0}] |
130- | Eliot | Ron | 2 | [{Ron, Andrew, 3, 0}] |
131- | Ron | Andrew | 3 | [{Andrew, null, 4, 0}] |
132- | Andrew | null | 4 | [] |
133- | Asya | Ron | 5 | [{Ron, Andrew, 3, 0}] |
134- | Dan | Andrew | 6 | [{Andrew, null, 4, 0}] |
135- +--------+----------+----+------------------------+
126+ +--------+----------+----+------------------------------------------------------ +
127+ | name | reportsTo| id | reportingHierarchy |
128+ +--------+----------+----+------------------------------------------------------ +
129+ | Dev | Eliot | 1 | [{name: Eliot, reportsTo: Ron, id: 2, level: 0}] |
130+ | Eliot | Ron | 2 | [{name: Ron, reportsTo: Andrew, id: 3, level: 0}] |
131+ | Ron | Andrew | 3 | [{name: Andrew, reportsTo: null, id: 4, level: 0}] |
132+ | Andrew | null | 4 | [] |
133+ | Asya | Ron | 5 | [{name: Ron, reportsTo: Andrew, id: 3, level: 0}] |
134+ | Dan | Andrew | 6 | [{name: Andrew, reportsTo: null, id: 4, level: 0}] |
135+ +--------+----------+----+------------------------------------------------------ +
136136```
137137
138- The depth field ` level ` is appended to each document in the result array. A value of ` 0 ` indicates the first level of matches.
138+ The depth field ` level ` is added to each struct in the result array. A value of ` 0 ` indicates the first level of matches.
139139
140140## Example 3: Limited Depth Traversal
141141
@@ -153,16 +153,16 @@ source = employees
153153The query returns the following results:
154154
155155``` text
156- +--------+----------+----+--------------------------------------+
157- | name | reportsTo| id | reportingHierarchy |
158- +--------+----------+----+--------------------------------------+
159- | Dev | Eliot | 1 | [{Eliot, Ron, 2}, {Ron, Andrew, 3}] |
160- | Eliot | Ron | 2 | [{Ron, Andrew, 3}, {Andrew, null, 4}]|
161- | Ron | Andrew | 3 | [{Andrew, null, 4}] |
162- | Andrew | null | 4 | [] |
163- | Asya | Ron | 5 | [{Ron, Andrew, 3}, {Andrew, null, 4}]|
164- | Dan | Andrew | 6 | [{Andrew, null, 4}] |
165- +--------+----------+----+--------------------------------------+
156+ +--------+----------+----+--------------------------------------------------------------------------------- +
157+ | name | reportsTo| id | reportingHierarchy |
158+ +--------+----------+----+--------------------------------------------------------------------------------- +
159+ | Dev | Eliot | 1 | [{name: Eliot, reportsTo: Ron, id: 2}, {name: Ron, reportsTo: Andrew, id: 3}] |
160+ | Eliot | Ron | 2 | [{name: Ron, reportsTo: Andrew, id: 3}, {name: Andrew, reportsTo: null, id: 4}] |
161+ | Ron | Andrew | 3 | [{name: Andrew, reportsTo: null, id: 4}] |
162+ | Andrew | null | 4 | [] |
163+ | Asya | Ron | 5 | [{name: Ron, reportsTo: Andrew, id: 3}, {name: Andrew, reportsTo: null, id: 4}] |
164+ | Dan | Andrew | 6 | [{name: Andrew, reportsTo: null, id: 4}] |
165+ +--------+----------+----+--------------------------------------------------------------------------------- +
166166```
167167
168168With ` maxDepth=1 ` , the traversal goes two levels deep (depth 0 and depth 1).
@@ -192,15 +192,15 @@ source = airports
192192The query returns the following results:
193193
194194``` text
195- +---------+------------+---------------------+
196- | airport | connects | reachableAirports |
197- +---------+------------+---------------------+
198- | JFK | [BOS, ORD] | [{JFK, [BOS, ORD]}] |
199- | BOS | [JFK, PWM] | [{BOS, [JFK, PWM]}] |
200- | ORD | [JFK] | [{ORD, [JFK]}] |
201- | PWM | [BOS, LHR] | [{PWM, [BOS, LHR]}] |
202- | LHR | [PWM] | [{LHR, [PWM]}] |
203- +---------+------------+---------------------+
195+ +---------+------------+----------------------------------------------- +
196+ | airport | connects | reachableAirports |
197+ +---------+------------+----------------------------------------------- +
198+ | JFK | [BOS, ORD] | [{airport: JFK, connects: [BOS, ORD]}] |
199+ | BOS | [JFK, PWM] | [{airport: BOS, connects: [JFK, PWM]}] |
200+ | ORD | [JFK] | [{airport: ORD, connects: [JFK]}] |
201+ | PWM | [BOS, LHR] | [{airport: PWM, connects: [BOS, LHR]}] |
202+ | LHR | [PWM] | [{airport: LHR, connects: [PWM]}] |
203+ +---------+------------+----------------------------------------------- +
204204```
205205
206206## Example 5: Cross-Index Graph Lookup
@@ -226,13 +226,13 @@ source = travelers
226226The query returns the following results:
227227
228228``` text
229- +-------+----------------+---------------------+
230- | name | nearestAirport | reachableAirports |
231- +-------+----------------+---------------------+
232- | Dev | JFK | [{JFK, [BOS, ORD]}] |
233- | Eliot | JFK | [{JFK, [BOS, ORD]}] |
234- | Jeff | BOS | [{BOS, [JFK, PWM]}] |
235- +-------+----------------+---------------------+
229+ +-------+----------------+----------------------------------------------- +
230+ | name | nearestAirport | reachableAirports |
231+ +-------+----------------+----------------------------------------------- +
232+ | Dev | JFK | [{airport: JFK, connects: [BOS, ORD]}] |
233+ | Eliot | JFK | [{airport: JFK, connects: [BOS, ORD]}] |
234+ | Jeff | BOS | [{airport: BOS, connects: [JFK, PWM]}] |
235+ +-------+----------------+----------------------------------------------- +
236236```
237237
238238## Example 6: Bidirectional Traversal
@@ -251,11 +251,11 @@ source = employees
251251The query returns the following results:
252252
253253``` text
254- +------+----------+----+------------------------------------------------+
255- | name | reportsTo| id | connections |
256- +------+----------+----+------------------------------------------------+
257- | Ron | Andrew | 3 | [{Ron, Andrew, 3}, {Andrew, null, 4}, {Dan, Andrew, 6}] |
258- +------+----------+----+------------------------------------------------+
254+ +------+----------+----+----------------------------------------------------------------------------------------------------- +
255+ | name | reportsTo| id | connections |
256+ +------+----------+----+----------------------------------------------------------------------------------------------------- +
257+ | Ron | Andrew | 3 | [{name: Ron, reportsTo: Andrew, id: 3}, {name: Andrew, reportsTo: null, id: 4}, {name: Dan, reportsTo: Andrew, id: 6}] |
258+ +------+----------+----+----------------------------------------------------------------------------------------------------- +
259259```
260260
261261With bidirectional traversal, Ron's connections include:
@@ -294,17 +294,17 @@ source = travelers
294294
295295** Normal mode** (default): Each traveler gets their own list of reachable airports
296296``` text
297- | name | nearestAirport | reachableAirports |
298- |-------|----------------|-------------------|
299- | Dev | JFK | [JFK, BOS, ORD] |
300- | Jeff | BOS | [BOS, JFK, PWM] |
297+ | name | nearestAirport | reachableAirports |
298+ |-------|----------------|-------------------------------------- |
299+ | Dev | JFK | [{airport: JFK, connects:[ BOS, ORD]}] |
300+ | Jeff | BOS | [{airport: BOS, connects:[ JFK, PWM]}] |
301301```
302302
303303** Batch mode** : A single row with all travelers and all reachable airports combined
304304``` text
305- | travelers | reachableAirports |
306- |----------------------------------------| -----------------------------|
307- | [{Dev, JFK}, {Jeff, BOS}] | [JFK, BOS, ORD, PWM , ...] |
305+ | travelers | reachableAirports |
306+ |--------------------------------------------------------------------|-------------------------------- -----------------------------|
307+ | [{name: Dev, nearestAirport: JFK}, {name: Jeff, nearestAirport: BOS}] | [{airport: JFK, connects:[ BOS, ORD]}, {airport:BOS , ...} ] |
308308```
309309
310310## Array Field Handling
0 commit comments