Deploy full-text index¶
Nebula Graph full-text indexes are powered by Elasticsearch. This means that you can use Elasticsearch full-text query language to retrieve what you want. Full-text indexes are managed through built-in procedures. They can be created only for variable STRING
and FIXED_STRING
properties when the listener cluster and the Elasticsearch cluster are deployed.
Precaution¶
Before you start using the full-text index, please make sure that you know the restrictions.
Deploy Elasticsearch cluster¶
To deploy an Elasticsearch cluster, see Kubernetes Elasticsearch deployment or Elasticsearch installation.
When the Elasticsearch cluster is started, add the template file for the Nebula Graph full-text index. For more information on index templates, see Elasticsearch Document.
Take the following sample template for example:
{
"template": "nebula*",
"settings": {
"index": {
"number_of_shards": 3,
"number_of_replicas": 1
}
},
"mappings": {
"properties" : {
"tag_id" : { "type" : "long" },
"column_id" : { "type" : "text" },
"value" :{ "type" : "keyword"}
}
}
}
Make sure that you specify the following fields in strict accordance with the preceding template format:
"template": "nebula*"
"tag_id" : { "type" : "long" },
"column_id" : { "type" : "text" },
"value" :{ "type" : "keyword"}
Caution
When creating a full-text index, start the index name with nebula
.
For example:
curl -H "Content-Type: application/json; charset=utf-8" -XPUT http://127.0.0.1:9200/_template/nebula_index_template -d '
{
"template": "nebula*",
"settings": {
"index": {
"number_of_shards": 3,
"number_of_replicas": 1
}
},
"mappings": {
"properties" : {
"tag_id" : { "type" : "long" },
"column_id" : { "type" : "text" },
"value" :{ "type" : "keyword"}
}
}
}'
You can configure the Elasticsearch to meet your business needs. To customize the Elasticsearch, see Elasticsearch Document.
Sign in to the text search clients¶
When the Elasticsearch cluster is deployed, use the SIGN IN
statement to sign in to the Elasticsearch clients. Multiple elastic_ip:port
pairs are separated with commas. You must use the IPs and the port number in the configuration file for the Elasticsearch.
Syntax¶
SIGN IN TEXT SERVICE (<elastic_ip:port>, {HTTP | HTTPS} [,"<username>", "<password>"]) [, (<elastic_ip:port>, ...)];
Example¶
nebula> SIGN IN TEXT SERVICE (127.0.0.1:9200, HTTP);
Note
Elasticsearch does not have a username or password by default. If you configured a username and password, you need to specify them in the SIGN IN
statement.
Show text search clients¶
The SHOW TEXT SEARCH CLIENTS
statement can list the text search clients.
Syntax¶
SHOW TEXT SEARCH CLIENTS;
Example¶
nebula> SHOW TEXT SEARCH CLIENTS;
+-------------+------+
| Host | Port |
+-------------+------+
| "127.0.0.1" | 9200 |
| "127.0.0.1" | 9200 |
| "127.0.0.1" | 9200 |
+-------------+------+
Sign out to the text search clients¶
The SIGN OUT TEXT SERVICE
statement can sign out all the text search clients.
Syntax¶
SIGN OUT TEXT SERVICE;
Example¶
nebula> SIGN OUT TEXT SERVICE;