This is a document for PGroonga 2.X and 3.X. See PGroonga 1.x document when you're using old PGroonga.
&@
operator for jsonb
typeSince 1.2.1.
&@
operator performs full text search against all texts in jsonb
by one keyword.
column &@ keyword
column
is a column to be searched. It's jsonb
type.
keyword
is a keyword for full text search. It's text
type.
You need to specify one of the following operator classes to use this operator:
pgroonga_jsonb_ops_v2
: Default for jsonb
pgroonga_jsonb_ops
: For jsonb
Here are sample schema and data for examples:
CREATE TABLE logs (
record jsonb
);
CREATE INDEX pgroonga_logs_index ON logs USING pgroonga (record);
INSERT INTO logs
VALUES ('{
"message": "Server is started.",
"host": "www.example.com",
"tags": [
"web",
"example.com"
]
}');
INSERT INTO logs
VALUES ('{
"message": "GET /",
"host": "www.example.com",
"code": 200,
"tags": [
"web",
"example.com"
]
}');
INSERT INTO logs
VALUES ('{
"message": "Send to <info@example.com>.",
"host": "mail.example.net",
"tags": [
"mail",
"example.net"
]
}');
You can perform full text search with one keyword by &@
:
(It uses jsonb_pretty()
function provided since PostgreSQL 9.5 for readability.)
SELECT jsonb_pretty(record) FROM logs WHERE record &@ 'server';
-- jsonb_pretty
-- -------------------------------------
-- { +
-- "host": "www.example.com", +
-- "tags": [ +
-- "web", +
-- "example.com" +
-- ], +
-- "message": "Server is started."+
-- }
-- (1 row)
&?
operator: Full text search against all text data in jsonb
by easy to use query language
&`
operator: Advanced search by ECMAScript like query language
@>
operator: Search by a jsonb
data