cho*_*oco 20 postgresql full-text-search json
所以我有一jsonb列有这样的条目:https : //pastebin.com/LxJ8rKk4
有没有办法对整个jsonb列实现全文搜索?
Eva*_*oll 21
PostgreSQL 10在 JSONB 上引入全文搜索
CREATE INDEX ON table
USING gin ( to_tsvector('english',jsondata) );
Run Code Online (Sandbox Code Playgroud)
JSON 上的新 FTS 索引与短语搜索一起使用,并跳过 JSON 标记和键。
您可以使用 jsonb 列jsonb_to_tsvector('<language>', <jsonb_column>, <filter>)(或使用 json 列json_to_tsvector)创建 GiST 或 GIN 索引
过滤器可以是以下任意组合'["string", "numeric", "boolean", "key", "all"]'。前三个与您要包含的值类型有关,同时"key"包含所有键。
例如:
CREATE TABLE test (
titles jsonb,
titles_tsvector tsvector generated always as(
jsonb_to_tsvector('english', titles, '["string"]')
) stored
)
Run Code Online (Sandbox Code Playgroud)
请参阅文档并搜索“jsonb_to_tsvector”(v13+)或“json(b)_to_tsvector”(v11、v12)