Skip to content

Full-text search

LOOKUP ON {<tag> | <edge_type>} WHERE <expression> [YIELD <return_list>]

<expression> ::=
    PREFIX | WILDCARD | REGEXP | FUZZY

<return_list>
    <prop_name> [AS <prop_alias>] [, <prop_name> [AS <prop_alias>] ...]
  • PREFIX(schema_name.prop_name, prefix_string, row_limit, timeout)
  • WILDCARD(schema_name.prop_name, wildcard_string, row_limit, timeout)
  • REGEXP(schema_name.prop_name, regexp_string, row_limit, timeout)
  • FUZZY(schema_name.prop_name, fuzzy_string, fuzziness, operator, row_limit, timeout)
    • fuzziness (optional): Maximum edit distance allowed for matching. The default value is AUTO. For other valid values and more information, see Elasticsearch document.
    • operator (optional): Boolean logic used to interpret text. Valid values are OR (default) and AND.
  • row_limit (optional): Specifies the number of rows to return. The default value is 100.
  • timeout (optional): Specifies the timeout time. The default value is 200ms.

Use the LOOKUP ON statement to do full-text search. The search string is specified in the WHERE clause. Before doing a full-text search, make sure that you deployed a Elasticsearch cluster and a Listener cluster. For more information, see Deploy Elasticsearch and Deploy Listener.

Before you start

Before you start using the full-text index, please make sure that you know the restrictions.

A natural language search interprets the search string as a phrase in natural human language. The search is case-insensitive.

Examples

nebula> CREATE SPACE basketballplayer (partition_num=3,replica_factor=1, vid_type=fixed_string(30));
nebula> SIGN IN TEXT SERVICE (127.0.0.1:9200);
nebula> USE basketballplayer;
nebula> ADD LISTENER ELASTICSEARCH 192.168.8.5:46780;
nebula> CREATE TAG player(name string, age int);
nebula> CREATE TAG INDEX name ON player(name(20));
nebula> 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);


nebula> LOOKUP ON player WHERE PREFIX(player.name, "B");
+-----------------+
| _vid            |
+-----------------+
| "Boris Diaw"    |
+-----------------+
| "Ben Simmons"   |
+-----------------+
| "Blake Griffin" |
+-----------------+

nebula> LOOKUP ON player WHERE WILDCARD(player.name, "*ri*") YIELD player.name, player.age;
+-----------------+-----------------+-----+
| _vid            | name            | age |
+-----------------+-----------------+-----+
| "Chris Paul"    | "Chris Paul"    | 33  |
+-----------------+-----------------+-----+
| "Boris Diaw"    | "Boris Diaw"    | 36  |
+-----------------+-----------------+-----+
| "Blake Griffin" | "Blake Griffin" | 30  |
+-----------------+-----------------+-----+

nebula> LOOKUP ON player WHERE WILDCARD(player.name, "*ri*") | YIELD count(*);
+----------+
| COUNT(*) |
+----------+
| 3        |
+----------+

nebula> LOOKUP ON player WHERE REGEXP(player.name, "R.*") YIELD player.name, player.age;
+---------------------+---------------------+-----+
| _vid                | name                | age |
+---------------------+---------------------+-----+
| "Russell Westbrook" | "Russell Westbrook" | 30  |
+---------------------+---------------------+-----+

nebula> LOOKUP ON player WHERE REGEXP(player.name, ".*");
+---------------------+
| _vid                |
+---------------------+
| "Danny Green"       |
+---------------------+
| "David West"        |
+---------------------+
| "Russell Westbrook" |
+---------------------+
...

nebula> LOOKUP ON player WHERE FUZZY(player.name, "Tim Dunncan", AUTO, OR) YIELD player.name;
+--------------+--------------+
| _vid         | name         |
+--------------+--------------+
| "Tim Duncan" | "Tim Duncan" |
+--------------+--------------+

Last update: April 13, 2021
Back to top