Inverted query

Updated at:

Syntax

  • The syntax for an inverted query (sub_syntax) is similar to the ES query syntax.

  • The sub_syntax is described in JSON. However, the curly braces {} in JSON conflict with the existing iGraph syntax. Therefore, you must escape all curly braces as \{ \}.

  • Inverted queries support four query types: single term, AND, OR, and ANDNOT.

Single term

  • You can use "match" to retrieve data based on an index.

  • "name" specifies the name of the indexed field to query.

Even if the "name" field is indexed as a numeric type, you must enclose the search keyword in double quotation marks. Otherwise, the query fails.

You must add an index configuration for the corresponding field on the table configuration page. Otherwise, the query fails.

\{"match": \{ "name" : "Liu Dehua"\} \}

AND

  • The "and" node must have two or more child nodes.

  • The child nodes of "and" can be `match`, `and`, or `or`.

\{  "and" : [       \{ "match" : \{ "name" : "Liu Dehua"\} \},       \{ "match" : \{ "id"   : "102" \} \},       \{ "or"    : \{ ...... \} \}   ]\}

OR

  • The "or" node must have two or more child nodes.

  • The child nodes of "or" can be `match`, `and`, or `or`.

\{   "or" : [              \{ "match" : \{ "name" : "Liu Dehua"\} \},       \{ "match" : \{ "id"   : "102" \} \},       \{ "and"   : \{ ...... \} \}    ]\}

ANDNOT

  • The "andnot" node must have two or more child nodes.

  • T1 ANDNOT T2 ANDNOT ... ANDNOT Tn is equivalent to T1 ANDNOT (T2 OR T3 ... OR Tn).

\{  "andnot" : [      "match" : \{ "name" : "Andy Lau"\},      "match" : \{ ...... \}   ]\}

Examples

Gremlin

  • For inverted retrieval, use indexQuery.

  • If an `indexQuery` step modifies a `V` step, the input parameter for the `V` step can be empty.

  • You cannot use inverted queries on kv or kkv tables.

g("graph_name").V().hasLabel("thinkerpop_modern_software_index").indexQuery("{\"match\":{\"lang\":\"java\"}}")==> {"label":"thinkerpop_modern_software_index","lang":"java","name":"ripple","pk":"5"}

Notes

  • The rate of real-time data updates to the inverted table should not exceed 5,000 QPS, because a higher rate can significantly affect query performance.

  • By default, inverted queries are truncated. The truncation limit is 3,000 results per column.

  • Example:

    • Question: A field `f1` has the value "a,b,c,d". How can you combine `or` and `match` to find entries where `f1` contains "a" or "c"?

    • Answer: When you configure `f1` as an indexed field, you must specify a tokenizer. For more information, see the section on index configuration. When the index is created, separate inverted indexes are built for "a", "b", "c", and "d". You can then use operators such as `match`, `or`, and `and` to create combined queries.