Search code examples
cloudant

"Unknown Error: mango_idx :: {no_usable_index,missing_sort_index}"}


I have the following query:

{'type': 'text', 
 'name': 'album-rating-text', 
 'index': {'fields': [
                      {'type': 'string', 'name': 'user_id'}, 
                      {'type': 'string', 'name': 'album_id'}, 
                      {'type': 'number', 'name': 'timestamp'}
]}}

Here is the query:

{'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'
                      ]
}}]}}

The error:

{ 
 "error":"unknown_error",
 "reason":"Unknown Error: mango_idx :: {no_usable_index,missing_sort_index}"
}

I've seen a similar question however, all the fields that I'm indexing on are in my sort list.


Update:

As a workaround, I attempted to simplify by dropping the timestamp field:

{"type": "text", 
 "name": "album-rating-text", 
 "index": {"fields": [
               {"type": "string", "name": "user_id"}, 
               {"type": "string", "name": "album_id"}
 ]}}

And query as so ...

{"selector": {"$and": [
                   {"user_id": {"$eq": "[email protected]"}}, 
                   {"album_id": {"$in": ["bf129f0d", "380e3a05"]}
              }]}, 
 "fields": ["user_id", "album_id"]}

I get the following error:

 {"warning":"no matching index found, create an index to optimize query time",
"docs":[
]}

Solution

  • If I remember correct, my query requirements changed and I chose to use a standard Cloudant Search index instead of a Mango index.