Lee
Lee

Reputation: 3104

Cloudant using text index on sorting

Hi I was trying to query from Cloudant and sort the results by name, so I created this text index (I used text index instead of JSON index because if I am not mistaken, this way I can get the "bookmark" value on return object).

{
 "type": "text",
 "def": {
  "default_analyzer": "keyword",
  "default_field": {},
  "selector": {},
  "fields": [
   {
    "Name": "string"
   }
  ],
  "index_array_lengths": true
 }
}

And here's my query

{
  "selector": {
    "Type": "people"
  },
  "fields": [
    "_id",
    "_rev",
    "Name"
  ],
  "sort": [
     {"Name:string": "asc"}
  ],
  "limit": 3
}

But I keep getting this error message "There is no index available for this selector". Which part did I went wrong?

Upvotes: 0

Views: 479

Answers (1)

Breno Antunes
Breno Antunes

Reputation: 76

You can use search Index(JSON) and get the bookmark as response to make pagination. queries -> new search index

To search by name:

function(doc){ 
  index('default', doc.name, {'facet' :  true});
}

In the search call you have to pass the limit, bookmark(in the second call), sort.

example:

cloudant_host_url/_design/queries/_search/NAME_OF_THE_INDEX_SEARCH?q=WORD_YOU_ARE_SEARCHING&limit=5&sort=NAME&bookmark=BOOKMARK_GOT_IN_THE_PREVIOUS_CALL

You can search for others indexes, for example id:

function(doc){ 
  index('id', doc._id, {'facet' :  true});
}

The URL to get by id:

cloudant_host_url/_design/queries/_search/NAME_OF_THE_INDEX_SEARCH?q=*:* AND id:(ID_YOU_ARE_SEARCHING)&limit=5

You can combine both:

cloudant_host_url/_design/queries/_search/NAME_OF_THE_INDEX_SEARCH?q=WORD_YOU_ARE_SEARCHING AND id:(ID_YOU_ARE_SEARCHING)&limit=5

Upvotes: 0

Related Questions