我有以下查询:
{'type': 'text',
'name': 'album-rating-text',
'index': {'fields': [
{'type': 'string', 'name': 'user_id'},
{'type': 'string', 'name': 'album_id'},
{'type': 'number', 'name': 'timestamp'}
]}}
这是查询:
{'sort': [
{'user_id': 'desc'},
{'album_id': 'desc'},
{'timestamp': 'desc'}
],
'limit': 1,
'fields': ['user_id', 'album_id', 'timestamp'],
'selector': {
'$and': [
{'user_id': {'$eq': '[email protected]'}},
{'album_id': {'$in': ['bf129f0d', '380e3a05'
]
}}]}}
错误:
{
"error":"unknown_error",
"reason":"Unknown Error: mango_idx :: {no_usable_index,missing_sort_index}"
}
我见过一个类似的问题但是,我索引的所有字段都在我的排序列表中。
Update:
作为解决方法,我尝试通过删除时间戳字段来简化:
{"type": "text",
"name": "album-rating-text",
"index": {"fields": [
{"type": "string", "name": "user_id"},
{"type": "string", "name": "album_id"}
]}}
并这样查询...
{"selector": {"$and": [
{"user_id": {"$eq": "[email protected]"}},
{"album_id": {"$in": ["bf129f0d", "380e3a05"]}
}]},
"fields": ["user_id", "album_id"]}
我收到以下错误:
{"warning":"no matching index found, create an index to optimize query time",
"docs":[
]}