Couchdb 加快Cloudant查询类型文本索引
我们有一个具有这种结构的表:Couchdb 加快Cloudant查询类型文本索引,couchdb,cloudant,Couchdb,Cloudant,我们有一个具有这种结构的表: {_id:15_0, createdAt: 1/1/1, task_id:[16_0, 17_0, 18_0], table:”details”, a:b, c: d, more} 我们使用 { "index": {}, "name": "paginationQueryIndex", "type": "text" } 它是自动创建的 { "ddoc": "_design/28e8db44a5a0862xxx", "nam
{_id:15_0, createdAt: 1/1/1, task_id:[16_0, 17_0, 18_0], table:”details”, a:b, c: d, more}
我们使用
{
"index": {},
"name": "paginationQueryIndex",
"type": "text"
}
它是自动创建的
{
"ddoc": "_design/28e8db44a5a0862xxx",
"name": "paginationQueryIndex",
"type": "text",
"def": {
"default_analyzer": "keyword",
"default_field": {
},
"selector": {
},
"fields": [
],
"index_array_lengths": true
}
}
我们正在使用以下查询
{
"selector": {
"createdAt": { "$gt": 0 },
"task_id": { "$in": [ "18_0" ] },
"table": "details"
},
"sort": [ { "createdAt": "desc" } ],
"limit”: 20
}
第一次需要700-800毫秒,之后减少到500-600毫秒
为什么第一次要花更长的时间
有没有办法加快查询速度
如果类型为“text”,是否有向特定字段添加索引的方法?(而不是索引这些记录中的所有字段)您可以尝试更明确地创建索引,定义要索引的每个字段的类型,例如:
{
"index": {
"fields": [
{
"name": "createdAt",
"type": "string"
},
{
"name": "task_id",
"type": "string"
},
{
"name": "table",
"type": "string"
}
]
},
"name": "myindex",
"type": "text"
}
然后您的查询变成:
{
"selector": {
"createdAt": { "$gt": "1970/01/01" },
"task_id": { "$in": [ "18_0" ] },
"table": "details"
},
"sort": [ { "createdAt": "desc" } ],
"limit": 20
}
请注意,我使用了数据类型为字符串的字符串
如果您对性能感兴趣,请尝试从查询中逐个删除子句,以查看是否有子句导致了性能问题。您还可以查看查询的索引,查看它是否正确使用索引
有关创建显式文本查询索引的文档如下所示