Game Data - Setting up Indexes

In the Configurator, you can set up Game Data Indexes for the custom data you'll persist for your game in the platform using the Game Data Service. When you set up indexed fields for your custom data in this way, you can then query them:

When you’ve done this work in the Configurator to set up indexes for your data, you can insert data, either using the Data Explorer or through Cloud Code, and then query that data using those indexed fields:

Accessing Data by id only? If you are only going to access a game data document by id, you don't need to add and configure any indexed fields. You'll be able to find these documents by id without defining any indexed fields.

Add Indexes Later? If you add game data in the Data Explorer or through Cloud Code without first setting up indexing fields, you can add indexed fields at a later date in the Configurator. You’ll then be able to query the data documents using those indexed fields.

Managing Data Persistence? For general guidelines and best practices to help you in deciding how to organize and manage data persistence on the GameSparks platform for your game, please review the Managing Data Persistence tutorial.

FAQs? You can review Frequently Asked Questions about creating and managing your Game Data.

Managing Game Data Indexes

The Configurator>Game Data page lists the Data Types for which you've added indexed fields:

You can use the following options (highlighted above):

Adding a Game Data Index

To add a new Game Data Index:

1. Click Configurator>Game Data. The Game Data page opens.

2. Click to Add a new Game Data Index. The Add Data Type Index page opens.

3. Enter the details of the custom Data Type for which you want to add indexed fields. In this example, we're going to add indexed fields for a Player Data Type:

Warning! The Short Code for a Data Type cannot contain an underscore character.

4. In the Indexed Fields panel, click to Add a new field for indexing the Data Type.

5. Enter the details of the indexed field:

Warning! The Short Code for an indexed field cannot contain an underscore or a period character.

6. Add any other indexed fields you want to use for querying the Data Type:

For the current example, we’ve added a total of three indexed fields:

Important! You can add a maximum of five indexed fields, at which point the Add button will be disabled.

Note: Alternatively, you can use a sample JSON document in the Index Advisor to set up your Data Type Indexes. See the following section for how to do this.

7. Click to Save and Close. You are returned to the Game Data page where the new Data Type with indexed fields is listed:

At this stage, it's important to note:

Using the Index Advisor

You can use the Index Advisor to add data indexes using a sample JSON document. This means you can quickly set up indexed fields for querying your custom data in those cases where you’ve already designed the data structures you want to persist against the platform.

1. Go to Configurator>Game Data and on the Game Data page, click to Edit the Data Type for which you want to set up indexing fields.

2. Under Indexed Fields, click to open the Index Advisor, which contains a JSON editor:

3. Enter the JSON document which you want to use to set up indexing fields for the Data Type. The JSON is scanned and candidate fields are listed with Path and Type entered automatically:

4. Click to add the field paths you want to use for indexing the Data Type. These should be the fields you want to query against, up to a maximum of five:

Note: The Short Code for an indexed field cannot contain an underscore character.

5. If the Type that is assigned to the field automatically is not what you want to use for querying, use the drop-down to change to the other Type. For example, in this case you might want to change the ARMOUR field to a String:

6. Click to Save and Close the Data Type Indexes you’ve set up using your sample JSON document.

Working with Game Data in Cloud Code

You can make use of the Game Data Service Cloud Code methods to store and access game data. As you enter your script, the usual script autocomplete functions in the Cloud Code editor invokes method selection and Help text:

API Documentation

For the Game Data Service API documentation pages, go to Cloud Code under API Documentation and then go to:

Building Script Queries in Cloud Code - Examples

Once you've reviewed the API documentation and started to use the Game Data Service Cloud Code methods, you can start to build queries to return data stored in your Data Types. You can use the following operators when building queries:

For example, to query for email strings:

Review Tutorials! See the following section for Game Data Service tutorials containing examples of how to build queries in Cloud Code.


Here are some tutorials that show how to persist and query data on the platform through Cloud Code using the Game Data Service:

Did this page help you? Please enter your feedback below.