Graph Queries And Indexes



Graph queries and Indexes

Querying Indexes

To query an index, define it as a data node using the explicit syntax.
Use from index rather than the ordinary "from", with the index name as a parameter:
with {from index 'Orders/ByCompany'} as orders

The following query for example uses the Orders/ByCompany index while searching for big orders made by German companies.

with {from index 'Orders/ByCompany' where Count > 10} as bigOrders

match
    (bigOrders) -
    [Company as company] ->
    (Companies as companies where Address.Country = "Germany")

How Are Graph Queries Indexed

Any graph query over the bare minimum is interpreted to several types of queries, each with its own measure of indexing and resource usage. Complex queries may combine methods mentioned here.

  • No Indexing
    This query creates no index, since retrieving a whole collection requires no searching.

    match 
        (Orders as orders)
  • Auto Indexing
    The node clause shown here will trigger RavenDB to create an auto index for queried orders, as done with non-graph queries.

    match 
        (Orders as orders 
            where ShipTo.Region = "Nueva Esparta")
  • Handled by the graph queries engine
    Queries with edges are handled by the graph queries engine before handing them to clients, to fathom the relations between data nodes.

    match 
        (Orders as orders)-
        [ShipVia as shipvia]->
        (Shippers as shippers)

Graph Queries and Map Reduce

It is sometimes "cheaper" to transfer work load from the graph engine to Map Reduce for the "heavy lifting", and let the graph engine handle just the final results.
To do this, create static Map Reduce definitions for datasets you intend to include in edge clauses.