不选择索引 - 在 N1QL 中查询对象 -> 数组 -> 对象时

Not picking Index - when querying Object -> array -> Object in N1QL

使用N1QL匹配属于一个国家的所有客户时没有选择索引 注意:bucket 大约有 10 条缺失记录,文档在 50 秒后获取,

查询

select * from `user-prof`   WHERE ANY item IN devices.location SATISFIES item.country IN ["US"] 

指数

CREATE INDEX id_userProfile ON `user-prof`  ( ALL ARRAY v.country FOR v IN devices.location END  )

文档

[
  {
    "customers": {
      "devices": {
        "user": "u1",
        "custid": "14CE5534CCE",
        "token": "4D5BE85896833148D696A1397C",
        "guest": {
          "lastActive": null,
          "searches": [

          ]
        },
        "latt": "6655059908",
        "locale": "en-US",
        "location": [
          {
            "city": "Afc",
            "country": "IN"
          },
          {
            "city": "Newyork",
            "country": "US"
          },
          {
            "city": null,
            "country": null
          }
        ],
        "long": "4.21787927806",
        "notify": {
          "Stats": false 
        },
        "tier": null,
        "tmz": "EU",
        "version": "0.1"
      }
    }
  },
   {
    "customers": {
      "devices": {
        "user": "u2",
        "custid": "64CE5534CC1E",
        "token": "6D5BE85896833148D696A1397C",
        "guest": {
          "lastActive": null,
          "searches": [

          ]
        },
        "latt": "6655059908",
        "locale": "en-US",
        "location": [
              {
            "city": "Texas",
            "country": "US"
          },
          {
            "city": null,
            "country": null
          }
        ],
        "long": "4.21787927806",
        "notify": {
          "Stats": false 
        },
        "tier": null,
        "tmz": "EU",
        "version": "0.1"
      }
    }
  }

您使用的是 Pre 4.6.2 ANY 子句中的变量需要与 CREATE INDEX 中的变量相同(即 item ,v )

https://developer.couchbase.com/documentation/server/current/n1ql/n1ql-language-reference/indexing-arrays.html