Configure Query Indexes
Indexes are used in querying for efficiency. They are based on the type of a class. The user may further specify the attributes of the class on which indexes are required.
Note
This feature is also available in NCache Professional.
Note
It is recommended to use JSON Query Indexing for Node.js.
Query Indexes can be configured in the following ways:
Define Query Indexes
You will need to define query indexes on the cache to perform operations on them. This can be done in the following ways:
Using the NCache Management Center
Launch the NCache Management Center by browsing to http://localhost:8251 or
<server-ip>:8251
for Windows and Linux.In the left navigation bar, click on Clustered Caches or Local Caches, based on the cache to which the query index will be added. Against the cache name, click on View Details. Make sure that the cache is stopped.
This opens the detailed configuration page for the cache. Go to the Advanced Settings tab and click on Query Indexes in the left bar.
This opens the Query Indexes page, click on Add.
On the next page, select the assembly that contains the classes that you want to store in the cache for query by clicking on the Browse button.
In the Selected Assemblies box, all serialized classes are displayed. Check the ones you want to index, and click on Add Selected Classes.
Note
The NCache Management Center displays all attributes and properties of selected classes.
- The added classes along with their attributes will be displayed in the List of selected classes. You can uncheck class attributes if you don't want to index them. You can also remove selected classes by clicking on Remove Selected Classes.
- The added query indexes will be displayed on the Query Indexes page. Click on Save Changes to apply this configuration to the cache.
Using Command Line Tools
The add-queryindex tool enables the user to add query indexes for the objects to be added to the cache.
The following command adds id, name, category, unitsAvailable, and unitPrice attributes from the class Data.Product in query indexes for demoCache.
add-queryindex -cachename demoCache -assemblypath /user/product.json -class Data.Product -attributes "productid'$'name'$'category'$'price"
Manually Editing NCache Configuration
Important
Make sure the cache is stopped before making any configuration changes.
- Specify the query indexes through config.ncconf by adding the
<query-indexes>
and<query-class>
tags under the<cache-settings>
tag. The following example adds attributes of two classes, Product and Customer, as indexes:
<cache-settings ...>
<query-indexes>
<query-class id="Data.Product" name="Data.Product">
<query-attributes id="unitPrice" name="unitPrice" data-type="System.Int32"/>
<query-attributes id="unitsInStock" name="unitsInStock" data-type="System.Int32"/>
<query-attributes id="productID" name="productID" data-type="System.Int32"/>
<query-attributes id="productName" name="productName" data-type="System.String"/>
<query-attributes id="category" name="category" data-type="System.String"/>
<query-attributes id="isContinued" name="isContinued" data-type="System.Boolean"/>
</query-class>
</query-indexes>
</cache-settings>
- Once changes are made, restart the NCache Service and start your cache.
Removing Query Indexes
Pre-defined query indexes can be removed by the user using the following steps.
Using the NCache Management Center
Launch the NCache Management Center by browsing to
<server-ip>:8251
(Linux) or http://localhost:8251 (Windows).In the left navigation bar, click on Clustered Caches or Local Caches from which you want to remove the configured query indexes. Against the cache name, click on View Details.
This opens up the detailed configuration page for the cache. Go to the Advanced Settings tab and click on Query Indexes in the left bar.
This opens up the Query Indexes page which shows existing classes for query indexes.
Select the classes or attributes you want to remove and click on Remove.
- Click on Save Changes to apply this configuration to the cache.
Using Command Line Tools
The remove-queryindex tool enables the user to remove pre-defined query indexes for the objects to be added to the cache.
The following command removes query indexing for the class Customer from the cache demoCache.
remove-queryindex -cachename demoCache -class Data.Product
See Also
Create a Cache
Remove Cache
Remove Server Node
Add Test Data