小编rus*_*ils的帖子

如何在Postgresql中对复杂的嵌套JSONB实现全文搜索

我将非常复杂的JSONB存储在一jsonb列中.

DB表看起来像:

 CREATE TABLE sites (
   id text NOT NULL,
   doc jsonb,
   PRIMARY KEY (id)
 )
Run Code Online (Sandbox Code Playgroud)

我们存储在doc列中的JSONB数据是一个复杂的嵌套数据:

   {
      "_id": "123",
      "type": "Site",
      "identification": "Custom ID",
      "title": "SITE 1",
      "address": "UK, London, Mr Tom's street, 2",
      "buildings": [
          {
               "uuid": "12312",
               "identification": "Custom ID",
               "name": "BUILDING 1",
               "deposits": [
                   {
                      "uuid": "12312",
                      "identification": "Custom ID",             
                      "audits": [
                          {
                             "uuid": "12312",         
                              "sample_id": "SAMPLE ID"                
                          }
                       ]
                   }
               ]
          } 
       ]
    }
Run Code Online (Sandbox Code Playgroud)

所以我的结构JSONB看起来像:

SITE 
  -> …
Run Code Online (Sandbox Code Playgroud)

postgresql full-text-search jsonb postgresql-9.5 postgresql-9.6

10
推荐指数
1
解决办法
1648
查看次数