本节介绍用于管理图中各类属性索引及LTE状态的方法。
索引
showIndex()
获取图中全部索引。
参数
config?: RequestConfig
:请求配置。
返回值
Index[]
:获取的索引列表。
// Retrieves indexes in the graph 'miniCircle'
const requestConfig: RequestConfig = { graph: "miniCircle" };
const indexList = await driver.showIndex(requestConfig);
for (const index of indexList) {
console.log(index);
}
Index {
id: '1',
name: 'test_index',
properties: 'year,float',
schema: 'account',
status: 'DONE',
size: undefined,
dbType: 0
}
Index {
id: '2',
name: 'year_index',
properties: 'year',
schema: 'account',
status: 'DONE',
size: undefined,
dbType: 0
}
Index {
id: '1',
name: 'targetPostInd',
properties: 'targetPost',
schema: 'disagree',
status: 'DONE',
size: undefined,
dbType: 1
}
showNodeIndex()
获取图中全部点索引。
参数
config?: RequestConfig
:请求配置。
返回值
Index[]
:获取的索引列表。
// Retrieves node indexes in the graph 'miniCircle'
const requestConfig: RequestConfig = { graph: "miniCircle" };
const indexList = await driver.showNodeIndex(requestConfig);
for (const index of indexList) {
console.log(index);
}
Index {
id: '1',
name: 'test_index',
properties: 'year,float',
schema: 'account',
status: 'DONE',
size: undefined,
dbType: 0
}
Index {
id: '2',
name: 'year_index',
properties: 'year',
schema: 'account',
status: 'DONE',
size: undefined,
dbType: 0
}
showEdgeIndex()
获取图中全部边索引。
参数
config?: RequestConfig
:请求配置。
返回值
Index[]
:获取的索引列表。
// Retrieves edge indexes in the graph 'miniCircle'
const requestConfig: RequestConfig = { graph: "miniCircle" };
const indexList = await driver.showEdgeIndex(requestConfig);
for (const index of indexList) {
console.log(index);
}
Index {
id: '1',
name: 'targetPostInd',
properties: 'targetPost',
schema: 'disagree',
status: 'DONE',
size: undefined,
dbType: 1
}
dropIndex()
从图中删除一个指定的索引。
参数
dbType: DBType
:索引类型(点或边)。indexName: string
:索引名称。config?: RequestConfig
:请求配置。
返回值
Response
:请求结果。
// Drops the node index 'test_index' from the graph 'miniCircle'
const requestConfig: RequestConfig = { graph: "miniCircle" };
const response = await driver.dropIndex(DBType.DBNODE, "test_index", requestConfig);
console.log(response.status?.message);
SUCCESS
dropNodeIndex()
从图中删除一个指定的点索引。
参数
indexName: string
:索引名称。config?: RequestConfig
:请求配置。
返回值
Response
:请求结果。
// Drops the node index 'test_index' from the graph 'miniCircle'
const requestConfig: RequestConfig = { graph: "miniCircle" };
const response = await driver.dropNodeIndex("test_index", requestConfig);
console.log(response.status?.message);
SUCCESS
dropEdgeIndex()
从图中删除一个指定的边索引。
参数
indexName: string
:索引名称。config?: RequestConfig
:请求配置。
返回值
Response
:请求结果。
// Drops the edge index 'targetPostInd' from the graph 'miniCircle'
const requestConfig: RequestConfig = { graph: "miniCircle" };
const response = await driver.dropEdgeIndex("targetPostInd", requestConfig);
console.log(response.status?.message);
SUCCESS
全文索引
showFulltext()
获取图中全部全文索引。
参数
config?: RequestConfig
:请求配置。
返回值
Index[]
:获取的全文索引列表。
// Retrieves full-text indexes in the graph 'miniCircle'
const requestConfig: RequestConfig = { graph: "miniCircle" };
const fulltextList = await driver.showFulltext(requestConfig);
for (const fulltext of fulltextList) {
console.log(fulltext);
}
Index {
id: undefined,
name: 'name',
properties: 'name',
schema: 'account',
status: 'DONE',
size: undefined,
dbType: 0
}
Index {
id: undefined,
name: 'Content',
properties: 'content',
schema: 'review',
status: 'DONE',
size: undefined,
dbType: 1
}
showNodeFulltext()
获取图中全部点的全文索引。
参数
config?: RequestConfig
:请求配置。
返回值
Index[]
:获取的全文索引列表。
// Retrieves node full-text indexes in the graph 'miniCircle'
const requestConfig: RequestConfig = { graph: "miniCircle" };
const fulltextList = await driver.showNodeFulltext(requestConfig);
for (const fulltext of fulltextList) {
console.log(fulltext);
};
Index {
id: undefined,
name: 'name',
properties: 'name',
schema: 'account',
status: 'DONE',
size: undefined,
dbType: 0
}
showEdgeFulltext()
获取图中全部边的全文索引。
参数
config?: RequestConfig
:请求配置。
返回值
Index[]
:获取的全文索引列表。
// Retrieves edge full-text indexes in the graph 'miniCircle'
const requestConfig: RequestConfig = { graph: "miniCircle" };
const fulltextList = await driver.showEdgeFulltext(requestConfig);
for (const fulltext of fulltextList) {
console.log(fulltext);
}
Index {
id: undefined,
name: 'Content',
properties: 'content',
schema: 'review',
status: 'DONE',
size: undefined,
dbType: 1
}
createFulltext()
在图中创建一个全文索引。
参数
dbType: DBType
:全文索引类型(点或边)。schemaName: string
:Schema名称。propertyName: string
:属性名称。fulltextName: string
:全文索引名称。config?: RequestConfig
:请求配置。
返回值
JobResponse
:请求结果。
// Creates a full-text index 'moviePlot' for the property 'plot' of the 'movie' nodes
const requestConfig: RequestConfig = { graph: "miniCircle" };
const response = await driver.createFulltext(DBType.DBNODE, "movie", "plot", "moviePlot", requestConfig);
const jobID = response.jobId;
await new Promise(resolve => setTimeout(resolve, 3000));
const jobs = await driver.showJob(jobID, requestConfig);
for (const job of jobs) {
console.log(`${job.id} - ${job.status}`);
}
19 - FINISHED
19_1 - FINISHED
createNodeFulltext()
在图中创建一个点的全文索引。
参数
schemaName: string
:Schema名称。propertyName: string
:属性名称。fulltextName: string
:全文索引名称。config?: RequestConfig
:请求配置。
返回值
JobResponse
:请求结果。
// Creates a full-text index 'moviePlot' for the property 'plot' of the 'movie' nodes
const requestConfig: RequestConfig = { graph: "miniCircle" };
const response = await driver.createNodeFulltext("movie", "plot", "moviePlot", requestConfig);
const jobID = response.jobId;
await new Promise(resolve => setTimeout(resolve, 3000));
const jobs = await driver.showJob(jobID, requestConfig);
for (const job of jobs) {
console.log(`${job.id} - ${job.status}`);
}
20 - FINISHED
20_1 - FINISHED
createEdgeFulltext()
在图中创建一个边的全文索引。
参数
schemaName: string
:Schema名称。propertyName: string
:属性名称。fulltextName: string
:全文索引名称。config?: RequestConfig
:请求配置。
返回值
JobResponse
:请求结果。
// Creates a full-text index 'agreeNotes' for the property 'notes' of the 'agree' edges
const requestConfig: RequestConfig = { graph: "miniCircle" };
const response = await driver.createEdgeFulltext("agree", "notes", "agreeNotes", requestConfig);
const jobID = response.jobId;
await new Promise(resolve => setTimeout(resolve, 3000));
const jobs = await driver.showJob(jobID, requestConfig);
for (const job of jobs) {
console.log(`${job.id} - ${job.status}`);
}
21 - FINISHED
21_1 - FINISHED
dropFulltext()
从图中删除一个指定的全文索引。
参数
dyType: DBType
:全文索引类型(点或边)。fulltextName: string
:全文索引名称。config?: RequestConfig
:请求配置。
返回值
Response
:请求结果。
// Drops the node full-index 'moviePlot' from the graph 'miniCircle'
const requestConfig: RequestConfig = { graph: "miniCircle" };
const response = await driver.dropFulltext(DBType.DBNODE, "moviePlot", requestConfig);
console.log(response.status?.message);
SUCCESS
LTE
lte()
将一个属性加载到计算引擎。
参数
dbType: DBType
:属性类型(点或边)。propertyName: string
:属性名称。schemaName: string
:Schema名称。config?: RequestConfig
:请求配置。
返回值
JobResponse
:请求结果。
// Loads the property 'year' of 'account' nodes to the computing engine
const requestConfig: RequestConfig = { graph: "miniCircle" };
const response = await driver.lte(DBType.DBNODE, "year", "account", requestConfig);
const jobID = response.jobId;
await new Promise(resolve => setTimeout(resolve, 3000));
const jobs = await driver.showJob(jobID, requestConfig);
for (const job of jobs) {
console.log(`${job.id} - ${job.status}`);
}
24 - FINISHED
24_1 - FINISHED
ufe()
将一个属性从计算引擎卸载。
参数
dbType: DBType
:属性类型(点或边)。propertyName: string
:属性名称。schemaName: string
:Schema名称。config?: RequestConfig
:请求配置。
返回值
Response
:请求结果。
// Unloads the property 'year' of 'account' nodes from the computing engine
const requestConfig: RequestConfig = { graph: "miniCircle" };
const response = await driver.ufe(DBType.DBNODE, "year", "account", requestConfig);
console.log(response.status?.message);
SUCCESS
完整示例
import { UltipaDriver } from "@ultipa-graph/ultipa-driver";
import { ULTIPA } from "@ultipa-graph/ultipa-driver/dist/types/index.js";
import { RequestConfig } from "@ultipa-graph/ultipa-driver/dist/types/types.js";
let sdkUsage = async () => {
const ultipaConfig: ULTIPA.UltipaConfig = {
// URI example: hosts: ["xxxx.us-east-1.cloud.ultipa.com:60010"]
hosts: ["10.xx.xx.xx:60010"],
username: "<username>",
password: "<password>"
};
const driver = new UltipaDriver(ultipaConfig);
// Retrieves indexes in the graph 'miniCircle'
const requestConfig: RequestConfig = { graph: "miniCircle" };
const indexList = await driver.showIndex(requestConfig);
for (const index of indexList) {
console.log(index);
}
};
sdkUsage().catch(console.error);