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

时间:2018-03-09 13:30:34

标签: nosql bigdata couchbase n1ql

使用N1QL匹配属于某个国家/地区的所有客户时,不会选择索引 注意:存储桶有大约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"
      }
    }
  }

1 个答案:

答案 0 :(得分:2)

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

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