Couchbase N1QL 数组查询

Couchbase N1QL array query

我的 giata_properties 存储桶中的文档示例:link

相关json粘贴

{
  "propertyCodes": {
    "provider": [
      {
        "code": [
          {
            "value": [
              {
                "value": "304387"
              }
            ]
          }
        ],
        "providerCode": "hotelbeds",
        "providerType": "gds"
      },
      {
        "code": [
          {
            "value": [
              {
                "name": "Country Code",
                "value": "EG"
              },
              {
                "name": "City Code",
                "value": "HRG"
              },
              {
                "name": "Hotel Code",
                "value": "91U"
              }
            ]
          }
        ],
        "providerCode": "gta",
        "providerType": "gds"
      }
    ]
  },
  "name": "Arabia Azur Resort"
}

我想要一个查询(和一个索引)来检索基于 propertyCodes.provider.code.value.valuepropertyCodes.provider.providerCode 的文档。我设法分别完成了每一项,但我不确定如何将它们合并到一个查询中。

SELECT meta().id FROM giata_properties AS gp USE INDEX(`#primary`) WHERE ANY v WITHIN gp.propertyCodes.provider[*].code SATISFIES v.`value` = '150613' END;

SELECT meta().id FROM giata_properties AS gp USE INDEX(`#primary`) WHERE ANY v within gp.propertyCodes.provider[*].providerCode SATISFIES v = 'hotelbeds' END;

因此,例如我想获取包含 304387propertyCodes.provider.code.value.value 并且 provider 也是 hotelbeds 的文档,因为代码值可以在文档中重复, 但代码和 providerCode 组合是唯一的。

这是查询和索引。

查询。

SELECT META().id
FROM giata_properties AS gp
WHERE ANY p IN propertyCodes.provider SATISFIES ( ANY v WITHIN p.code SATISFIES v.`value` = '304387' END ) AND p.providerCode = 'hotelbeds' END;

索引。

CREATE INDEX idx_value ON giata_properties
( DISTINCT ARRAY ( DISTINCT ARRAY v.`value` FOR v WITHIN p.code END ) FOR p IN propertyCodes.provider END );

CREATE INDEX idx_providerCode ON giata_properties
( DISTINCT ARRAY p.providerCode FOR p IN propertyCodes.provider END );