I want to make a full search query on a spécific value of my jsonb like the format of the json is :
{
"highlights": {
"concise": null,
"complete": null
},
"gist": {
"concise": [
{
"text": "",
"isHighlighted": false,
"highlightID": ""
}...
],
"complete": null
},
"summary": {
},
"followup": {
},
"subjects": {
...
}
i want do my research on gist.concise
I have already tri like that but doesn’t work :
SELECT
audio.id
FROM
audio
JOIN
audio_json ON audio.id = audio_json.audio_id
WHERE
to_tsvector(audio.name) @@ to_tsquery('ornithorinque')
OR to_tsvector(audio.context::text) @@ to_tsquery('ornithorinque')
OR to_tsvector(
audio_json.analysis ->> 'gist' ->> 'concise'::text
) @@ to_tsquery('ornithorinque');
2
Answers
the answer is:
to_tsvector((audio_json.analysis ->> 0)::jsonb ->> 'gist') @@ to_tsquery('ornithorinque')
Built-in JSONPath you can use with
jsonb
offerslike_regex
filter expression: demoHere,
@@
isjsonb
path predicate check operator.JSONB
is fast on its own and faster with an index, but queries withlike_regex
won’t qualify for index support. The advantage of Full Text Searchtsquery
andtsvector
is that they will be faster if you extract your text and index it, or build an expression index: