【问题标题】:Cloudant Query text "LIKE" search on a single fieldCloudant 查询文本“LIKE”搜索单个字段
【发布时间】:2016-12-20 21:01:37
【问题描述】:

我希望使用 Cloudant Query 来获取指定字段与字符串匹配的所有文档(类似于 SQL“LIKE”),但我不知道该怎么做。

我意识到我可以为此目的使用搜索索引,但我很想知道使用 Cloudant Query 的解决方案。

【问题讨论】:

    标签: cloudant


    【解决方案1】:

    您可以使用$regex 运算符,它允许您使用正则表达式模式。例如,

    {
        "selector": {
            "person": {
                "$regex": "Rob"
            }
        },
        "fields": [
            "person"
        ]
    }
    

    其他信息:
    https://docs.cloudant.com/cloudant_query.html#condition-operators

    【讨论】:

    • 您好,感谢您的帮助。如果我想在给定字符串的文档中搜索两个字段怎么办?我不能使用 { "index": {}, "type": "text" },因为我将搜索整个文档。
    【解决方案2】:

    要搜索多个字段,可以使用 Cloudant Query 的组合运算符,例如:

    {
      "selector": {
        "$or": [
          { "person": { "$regex": "Rob" }},
          { "pet":  { "$regex": "Rob" }}
        ]
      },
      "fields": [
        "person",
        "pet"
      ]
    }
    

    欲了解更多信息,请参阅https://docs.cloudant.com/cloudant_query.html#combination-operators

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-04
      • 1970-01-01
      • 2011-09-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多