Nebula-全文检索

连接ES

添加Nebula全文索引模板文件

http://localhost:5601/app/dev_tools#/console

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
curl -H "Content-Type: application/json; charset=utf-8" -XPUT http://localhost: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"}
}
}
}'

登录ES客户端

SIGN IN TEXT SERVICE (localhost:9200,"admin","123456")

查看ES客户端详情

SHOW TEXT SEARCH CLIENTS;

退出ES客户端

SIGN OUT TEXT SERVICE

配置Nebula

安装storage服务

进入/usr/local/nebula根目录下,进入/etc子目录,找到nebula-storaged-listener.conf.production文件,复制一份并去除.production后缀。将文件中的listenr地址改为真实地址。

随后启动listener:./bin/nebula-storaged --flagfile etc/nebula-storaged-listener.conf

添加listener

ADD LISTENER ELASTICSEARCH 192.168.100.1:9789,192.168.100.2:9789;(注:如果有多台图库集群,都要配置)

进入nebula-console,执行SHOW LISTENER可以查看图空间的所有listener。

要删除所有listener,执行:REMOVE LISTENER ELASTICSEARCH(注:一个图空间仅可执行一次)

刷表

创建图空间

1
CREATE SPACE nebula_graph (partition_num = 20, replica_factor = 2, vid_type = FIXED_STRING(128))

Tag

1
2
3
CREATE TAG IF NOT EXISTS player(name string, age string);
CREATE TAG INDEX IF NOT EXISTS name ON player(name(20),age(10));
CREATE FULLTEXT TAG INDEX nebula_index_1 ON player(name,age);

Edge Type

1
CREATE EDGE IF NOT EXISTS edge_player(created_time TIMESTAMP NULL DEFAULT now());

全文索引

注:1.要将图库索引同步到es中去,需要在创建索引时将索引以nebula为开头命名。

2.执行REBUILD FULLTEXT INDEX将索引同步到es,此时es中还未完成索引的创建,需要在图库录入数据后自动同步到es(可能存在延迟,时间不定)

3.仅可使用LOOKUP语句进行模糊检索

4.删除图空间,全文索引不会自动删除,需要手动执行:DROP FULLTEXT INDEX <nebula_index*>

查看全文索引

SHOW FULLTEXT INDEXES

数据测试

插入数据

1
2
3
4
5
6
7
8
9
10
11
12
INSERT VERTEX player(name, age) VALUES \
"Russell Westbrook": ("Russell Westbrook", 30), \
"Chris Paul": ("Chris Paul", 33),\
"Boris Diaw": ("Boris Diaw", 36),\
"David West": ("David West", 38),\
"Danny Green": ("Danny Green", 31),\
"Tim Duncan": ("Tim Duncan", 42),\
"James Harden": ("James Harden", 29),\
"Tony Parker": ("Tony Parker", 36),\
"Aron Baynes": ("Aron Baynes", 32),\
"Ben Simmons": ("Ben Simmons", 22),\
"Blake Griffin": ("Blake Griffin", 30);

模糊检索

LOOKUP ON player WHERE PREFIX(player.name, "B");

LOOKUP ON player WHERE WILDCARD(player.name, "*ri*") YIELD player.name, player.age;

LOOKUP ON player WHERE WILDCARD(player.name, "*ri*") | YIELD count(*);

LOOKUP ON player WHERE REGEXP(player.name, "R.*") YIELD player.name, player.age;

LOOKUP ON player WHERE REGEXP(player.name, ".*");

LOOKUP ON player WHERE FUZZY(player.name, "Tim Dunncan", AUTO, OR, 100) YIELD player.name;

Powered by Hexo and Hexo-theme-hiker

Copyright © 2017 - 2024 青域 All Rights Reserved.

UV : | PV :