couchdb - cloudant 按多个值搜索索引

标签 couchdb cloudant

Cloudant 正在返回错误消息:

{"error":"invalid_key","reason":"Invalid key use-index for this request."}

每当我尝试使用组合运算符“$or”查询索引时。

我的文档示例如下:

{
  "_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
        ]
      ]
    ]
  }
}

我创建的索引是为字段“properties.PageName”创建的,当我只查询一个文档时它工作正常,但是当我尝试多个文档时,我会收到错误响应,如开始。

如果有帮助,请调用: 发布https://xyz.cloudant.com/db/_find

请求正文:

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

最佳答案

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

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

然后我能够执行以下查询:

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

关于couchdb - cloudant 按多个值搜索索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33620321/

相关文章:

codeigniter - couchDB + codeigniter?

cloudant - 无法删除 Cloudant 中的 API key

json - 将 IBM 移动应用程序构建器连接到 Cloudant JSON 数据 - bluemix-mobile-services

couchdb - 创建 View 以检查文档字段的特定值(用于简单登录)

javascript - CouchDB OpenDoc 函数中的 JQuery TypeError

java - org.ektorp.InvalidDocumentException : Cannot resolve id accessor in class

java - Cloudant Java 客户端支持列表功能吗?

python - 使用 CouchDB 和 Python 的机器学习检测 'unusual behavior'?

couchdb适合这种情况吗?

mongodb - noSQL 和规范化数据