
Time for action – querying an Index
We will query the TotalOrdersPerCustomer
index and will apply a query expression to filter the index result using the Lucene
syntax query.
- In the Management Studio, select the Indexes tab to display the Indexes screen.
- Click on the
TotalOrdersPerCustomer
index to query it and display results in the Query Index Screen. - In the Query area, enter the following code snippet:
CustomerId: A54309
Tip
In the Query area, press Ctrl + Space to show the index fields list and select the
CustomerId
field. - Click on the Execute button to show the results of the query.
What just happened?
We queried the TotalOrdersPerCustomer
index and filtered the query result.
Once the result was displayed, we wrote a Lucene
query expression to filter that result and display all documents which matched the CustomerID = A54309
.
The query engine will search index result documents collection in the CustomerId
field matching the value we have specified. Think of it as the "where" clause parameter.
Creating a Dynamic Query
Dynamic queries refer to queries that don't specify which index they use. The Dynamic Query and Query Index screens have similarities and layouts the same. The only difference between the two screens is that instead of saying what index to use, you say what collection to query.
You can use the generic query designer to write a dynamic query expression using the Lucene
syntax. In the Dynamic Query screen, you can choose to query all documents or only a specific collection.
When creating a new dynamic query, RavenDB will create a temporary index and give it a name that starts with Temp/
. When a temporary index gets a significant usage, RavenDB may decide to promote it permanently. When this happens the name of the index will change from Temp/
to Auto/
. These indexes are really easy to spot in the Management Studio's Indexes screen. Also, you can promote a temporary index manually to permanent.
You can create a new dynamic query by clicking on the Dynamic Query button on the Indexes screen or by using the New Dynamic Query button on the Management Studio's main interface.