cloudant按多个值搜索索引

时间:2015-11-09 23:33:34

标签: couchdb cloudant

Cloudant返回错误消息:

  

{&#34;错误&#34;:&#34; invalid_key&#34;,&#34;原因&#34;:&#34;此请求的密钥使用索引无效。&#34;} < / p>

每当我尝试使用组合运算符查询索引时,&#34; $或&#34;。

我的文档的样本是:

{
  "_id": "28f240f1bcc2fbd9e1e5174af6905349",
  "_rev": "1-fb9a9150acbecd105f1616aff88c26a8",
  "type": "Feature",
  "properties": {
    "PageName": "A8",
    "PageNumber": 1,
    "Lat": 43.051523,
    "Long": -71.498852
  },
  "geometry": {
    "type": "Polygon",
    "coordinates": [
      [
        [
          -71.49978935969642,
          43.0508382914137
        ],
        [
          -71.49978564033566,
          43.052210148524
        ],
        [
          -71.49791499857444,
          43.05220740550381
        ],
        [
          -71.49791875962663,
          43.05083554852429
        ],
        [
          -71.49978935969642,
          43.0508382914137
        ]
      ]
    ]
  }
}

我创建的索引是针对字段&#34; properties.PageName&#34;,当我查询一个文档时它工作正常,但是当我尝试多个文档时,我会收到在开头引用的错误响应。

如果它有帮助,这是电话: 发布https://xyz.cloudant.com/db/_find

请求正文:

{
  "selector": {
    "$or": [
      { "properties.PageName": "A8" },
      { "properties.PageName": "M30" },
      { "properties.PageName": "AH30" } 
    ]
  },
  "use-index": "pagename-index"
}

1 个答案:

答案 0 :(得分:6)

要执行$or查询,您需要创建text(全文)索引,而不是json索引。例如,我刚刚创建了以下索引:

{
  "index": {
    "fields": [
      {"name": "properties.PageName", "type": "string"}
    ]
  },
  "type": "text"
}

然后我就可以执行以下查询:

{
  "selector": {
    "$or": [
      { "properties.PageName": "A8" },
      { "properties.PageName": "M30" },
      { "properties.PageName": "AH30" }
    ]
  }
}