title: ArangoDB AQL Filtering Using Edges and Vertices with Unknown Positions in Graph Traversal Path
body: <p>I have a generic graph structure where I need to find non-leaf nodes in the graph based on their connections to other nodes in the graph. The position of the node I want to return is not defined, and it is possible there are multiple paths to the node I want to return. I want to run a single query to return a bunch of items I am displaying in a sorted list to a client. I do not want to have to run multiple asynchronous queries and sort on the client side.</p>
  
  <p>This list is filtered based on the edges that connect the vertices together, or if the node is connected to another node. The filter conditions are updated on the client side, which results in the query being re-constructed and the database re-queried. The position of the nodes in the graph that need to be returned is not guaranteed to be the same for all results, they may be leaf nodes, or anywhere in the path. The vertices I want to return can be identified via attributes on the edges leading to them, or away from them. Each edge also has a date attribute on it that is used for sorting and a type attribute that is used for filtering.</p>
  
  <p>Image in a graph 'myGraph' such as I attempted to illustrate below.</p>
  
  <pre><code>------- 
  | v:1 |\
  ------- \
     | \   \ -------
     |  |   \| v:4 |\
     |  \    ------- \
     |   |  /   ^     \ -------
     |    \/    |      \| v:7 |
     |    /|  return    -------   
     |   /  \             
     |  /   |              
  -------   \
  | v:2 |\   |
  ------- \   \
     |     \ -------
     |      \| v:5 |\
     |       ------- \
     |                \ -------
     |                 \| v:8 |\
     |                  ------- \ 
     |                     ^     \ -------
     |                     |      \| v:10|
  -------                return    -------   
  | v:3 |\   
  ------- \   
           \ -------
            \| v:6 |\
             ------- \
                      \ -------
                       \| v:9 |
                        -------
                           ^
                           | 
                         return
  </code></pre>
  
  <p>The above diagram illustrates what I want to return given one set of filtering conditions, but the returned results can vary if I change the filtering conditions. The nodes I want to return are easily identified based on the attributes on the edges leading to them or away from them. </p>
  
  <p>I have a query that looks something like the following, but am having trouble finding a way to index the nodes in the path that have edges leading to or away from them that meet a specific filtering criteria. </p>
  
  <pre><code>FOR item in vertexCollection1
     FILTER .... // FILTER the vertices
     FOR v, e, p IN 1..4 OUTBOUND item._id GRAPH 'myGraph'
        // ?? Not sure how to efficiently return from here
        // ?? FILTER p.vertices[??].v == 7 OR p.vertices[??].v == 10
        // ?? FILTER p.edges[??].type == "type1" OR p.edges[??].type == "type2"... etc based on user selections
        // ?? LET date = p.edges[vertexPosition - 1].date 
        // ?? LET data = p.vertices[??]
        // SORT DATE_TIMESTAMP(date) DESC
        // RETURN {date: date, data: data}
  </code></pre>
  
  <p>I am currently using a [ ** ] operation to get the specific node based on what collection it resides in using something like the following:</p>
  
  <pre><code>LET data = p.vertices[ ** FILTER CONTAINS(CURRENT._id, "collectionName") OR ...]
  </code></pre>
  
  <p>but this is awkward and requires the vertices to be placed in specific collections to facilitate query construction. This also does not solve the problem of how to index the associated edges connecting to the node I want to return.</p>
  
  <p>I apologize if this question is answered elsewhere, and if it is a pointer to the answer is appreciated. I am not sure on the correct terminology to concisely describe the problem and search accordingly.</p>
  
  <p>Thanks!</p>