HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlMajor

How can I use a full-text search on a jsonb column with Postgres?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
canfullsearchcolumnwithpostgrestexthowusejsonb

Problem

So i have a jsonb column that has entries like this: https://pastebin.com/LxJ8rKk4

Is there any way to implement a full-text search on the entire jsonb column?

Solution

PostgreSQL 10+

PostgreSQL 10 introduces Full Text Search on JSONB

CREATE INDEX ON table
   USING gin ( to_tsvector('english',jsondata) );


The new FTS indexing on JSON works with phrase search and skips over both the JSON-markup and keys.

Code Snippets

CREATE INDEX ON table
   USING gin ( to_tsvector('english',jsondata) );

Context

StackExchange Database Administrators Q#179598, answer score: 24

Revisions (0)

No revisions yet.