PostgreSQL query on jsonb column is not using indexes

I have the following table and indexes where all those indexes were created to try and find a solution to my issue:

create table persistent_events (     "notificationId"                       text         not null         constraint persistent_events_pkey             primary key,     payload                                bytea        not null,     notification                           jsonb );   create index metadatadescriptionidx     on persistent_events (((notification -> 'metadata'::text) ->> 'description'::text));  create index metadataidx     on persistent_events ((notification ->> 'metadata'::text));  create index metadataidxgin     on persistent_events using gin ((notification -> 'metadata'::text));  create index metadatadescriptionidxgin     on persistent_events (((notification -> 'metadata'::text) -> 'description'::text));  create index metadataidx2     on persistent_events ((notification -> 'metadata'::text));  create index metadatadescriptionidx2     on persistent_events (((notification -> 'metadata'::text) -> 'description'::text));  create index metadataidx3     on persistent_events (jsonb_extract_path(notification, VARIADIC ARRAY ['metadata'::text]));  create index metadatadescriptionidx4     on persistent_events ((jsonb_extract_path(notification, VARIADIC ARRAY ['metadata'::text]) -> 'description'::text));  create index metadatadescriptionidx3     on persistent_events ((jsonb_extract_path(notification, VARIADIC ARRAY ['metadata'::text]) ->>                            'description'::text)); 

The data stored in the notification column is like the following, but the content of notificationData varies a lot.

{     "metadata":     {         "description": "Test event",         "notificationId": "5eaf73ac-c0b1-4e39-86cc-d5cf9f5f33190e"     },     "notificationData":     {         "attributesChangeInfo":         [             {                 "newValue": "host",                 "oldValue": "localhost",                 "attributeName": "something"             }         ]     } } 

If I query with the following statement everything works fine:

SELECT notification, payload FROM persistent_events WHERE ((notification->'metadata'->>'description' = 'Test event')); 

The execution plan is the following and it is using the indexes as expected:

Bitmap Heap Scan on persistent_events  (cost=93.12..15578.79 rows=4735 width=549) (actual time=2.076..2.078 rows=2 loops=1)   Recheck Cond: (((notification -> 'metadata'::text) ->> 'description'::text) = 'Test event'::text)   Heap Blocks: exact=1   ->  Bitmap Index Scan on metadatadescriptionidx  (cost=0.00..91.94 rows=4735 width=0) (actual time=0.845..0.846 rows=2 loops=1)         Index Cond: (((notification -> 'metadata'::text) ->> 'description'::text) = 'Test event'::text) Planning Time: 16.939 ms Execution Time: 2.177 ms 

If I write it with the following statement using jsonb_extract_path it is not using the indexes:

SELECT notification, payload FROM persistent_events,      jsonb_extract_path(notification, 'metadata') metadata0 WHERE ((metadata0->>'description' = 'Test event')); 

Plan:

Nested Loop  (cost=0.00..127054.49 rows=947014 width=549) (actual time=74.733..2566.834 rows=2 loops=1)   ->  Seq Scan on persistent_events  (cost=0.00..103379.14 rows=947014 width=549) (actual time=0.019..1457.983 rows=947014 loops=1)   ->  Function Scan on jsonb_extract_path metadata0  (cost=0.00..0.02 rows=1 width=0) (actual time=0.001..0.001 rows=0 loops=947014)         Filter: ((metadata0 ->> 'description'::text) = 'Test event'::text)         Rows Removed by Filter: 1 Planning Time: 0.849 ms JIT:   Functions: 6 "  Options: Inlining false, Optimization false, Expressions true, Deforming true" "  Timing: Generation 1.069 ms, Inlining 0.000 ms, Optimization 8.907 ms, Emission 63.872 ms, Total 73.849 ms" Execution Time: 2772.180 ms 

The problem is that I need to write most queries using jsonb_extract_path and jsonb_array_elements as the json contains different arrays that I need to filter on. Is there any way to have PostgreSQL use the indexes even if I use those two functions?