Updated on 2024-01-04 GMT+08:00

Creating an Index

Function

This API is used to create indexes based on the specified information such as indexName and IndexType. Currently, GES supports composite indexes and full-text indexes.

  • Composite indexes include GlobalCompositeVertexIndex, GlobalCompositeEdgeIndex, CompositeVertexIndex, and CompositeEdgeIndex. A composite index is created for a fixed combination of properties. A local index can be created on a specified label. You do not need to specify a label for a global composite index. As long as a label contains a specified property, an index is automatically created on the label. Indexes can be used to accelerate queries.
  • Full-text indexes (FullTextIndex) can implement functions such as full-text search and fuzzy search. If you search data immediately after an update, you may get the old data. You are advised to query the data 1 second after the update. For details about how to use full-text indexes, see Querying Vertices That Meet Filter Criteria and Querying Edges That Meet Filter Criteria. You can also use full-text indexes in Cypher statements. For details, see Performing Cypher Queries.
  • Full-text indexing is currently supported only by the database edition.
  • After an index is created, wait for 30 seconds for index synchronization. After the synchronization is complete, Cypher queries can be accelerated using the index.

Indexes

Feature

Fuzzy Search

Speed

Flexibility

Composite indexes

No

Fast

Fixed composite property keys only

Full-text indexes

Yes

Slower than composite indexes

Randomly combined property keys

URI

POST /ges/v1.0/{project_id}/graphs/{graph_name}/indices
Table 1 URI parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID. For details about how to obtain the project ID, see Obtaining a Project ID.

graph_name

Yes

String

Graph name

Request Parameters

Table 2 Request body parameters

Parameter

Mandatory

Type

Description

indexName

Yes

String

Index name. The name can contain a maximum of 63 characters. Only letters, digits, hyphens (-), and underscores (_) are allowed.

indexType

Yes

String

Index type, which is case sensitive

  • GlobalCompositeVertexIndex is a global composite vertex index.
  • GlobalCompositeEdgeIndex is a global composite edge index.
  • CompositeVertexIndex is a local composite vertex index.
  • CompositeEdgeIndex is a local composite edge index.
  • FullTextIndex is a full-text index.

hasLabel

No

Boolean

Whether labels exist. The default value is false.

  • true
  • false

indexLabel

No

List

Labels on which indexes are created. This parameter is available only when indexType is set to CompositeVertexIndex or CompositeEdgeIndex. This parameter is mandatory.

indexProperty

No (If hasLabel is false or null, this parameter is mandatory.)

List

Index property list

Indexes can be created for the following property types: integer, float, double, long, enum, string, and date.

  • If a property is of the string type, the value must be no more than 40 bytes. The excess part will be deleted.
  • Cypher queries can be accelerated with indexes whose hasLabel is True.
    • If indexProperty is left blank, the created index is a label index, which accelerates label filtering.
    • If indexProperty is specified, the created index is a property index, which accelerates property filtering.

Response Parameters

Table 3 Response body parameters

Parameter

Type

Description

errorMessage

String

System prompt.

  • If execution succeeds, this parameter may be left blank.
  • If execution fails, this parameter is used to display the error message.

errorCode

String

System prompt.

  • If execution succeeds, this parameter may be left blank.
  • If execution fails, this parameter is used to display the error code.

jobId

String

ID of an asynchronous job

NOTE:

You can view the job execution status and obtain the return result by querying the job ID. For details, see Job Management APIs.

jobType

String

Type of an asynchronous job

result

String

If the execution is successful, the value of result is success.

Example Request

Create a composite index. The index name is ageIndex and the index type is global vertex index.
POST http://{SERVER_URL}/ges/v1.0/{project_id}/graphs/{graph_name}/indices
{
    "indexName":"ageIndex",
    "indexType": "GlobalCompositeVertexIndex",

    "hasLabel": "true",
    "indexProperty": ["age"]
}

SERVER_URL: Address for accessing a graph. For details about its value, see Using Service Plane APIs.

Example Response

Status code: 200

Example response for a successful request

Http Status Code: 200
{
"jobId": "f99f60f1-bba6-4cde-bd1a-ff4bdd1fd500000168232",
"jobType": 8
}

Status code: 400

Example response for a failed request

Http Status Code: 400
{
  "errorMessage": "graph [demo] is not found",
  "errorCode": "GES.8603"
}

Status Codes

Return Value

Description

400 Bad Request

Request error.

401 Unauthorized

Authorization failed.

403 Forbidden

No operation permissions.

404 Not Found

No resources found.

500 Internal Server Error

Internal server error.

503 Service Unavailable

Service unavailable.

Error Codes

See Error Codes.