CouchDB 多值云搜索索引

ruarlubt  于 2023-02-06  发布在  CouchDB
关注(0)|答案(1)|浏览(198)

Cloudant返回错误消息:
{“错误”:“invalid_key”,“原因”:“此请求的键使用索引无效。"}
每当我尝试使用组合运算符“$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"
}
5hcedyr0

5hcedyr01#

为了执行$or查询,您需要创建一个text(全文)索引,而不是json索引。

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

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

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

相关问题