如何在CouchDB中使用CURL或HTTP API创建搜索索引?

时间:2016-05-19 17:40:11

标签: curl lucene couchdb cloudant

如何为此创建类似的设计:

{
   "_id": "_design/foo",
   "_rev": "1-166900c56b2e87d91bb48dcf890c84ed",
   "fulltext": {
       "by_title": {
           "index": "function(doc) { var ret=new Document(); ret.add(doc.title); return ret }"
       }
   }
}

取自本教程: BlogPost

我已经重新编译了我的CouchDB以允许couchdb-lucene。 github couchdb-lucene

我遇到的问题是我找不到任何合适的例子来尝试在没有UI的情况下插入设计,这只允许设计视图,而不是搜索索引

1 个答案:

答案 0 :(得分:2)

设计文档的创建方式与常规文档相同,因此您可以使用HTTP API for documents

您可以将设计保存在文件中,例如“yourdesign.json”,然后使用以下命令上传:

curl -H 'Content-Type: application/json' -X PUT http://127.0.0.1:5984/yourdb/_design/foo -d @yourdesign.json