geofrey
geofrey

Reputation: 466

Selector query using search index

Given the document:

{
  docId: "a1234",
  doc_type: "asset",
}

I have the following search index function in _design/assets with index name search_asset:

function(doc) {
   if (doc.doc_type !== 'asset') return;
   index('docId', doc.docId, { store: 'true', facet: 'true' });
}

However, when I try to search using the cloudant selector query:

{
  selector: { 
    docId: "a1234"
  },
  fields: ["docId"]      
}

It gives me this error: Error running query. Reason: (no_usable_index) There is no index available for this selector.

I also added the use_index option but that doesn't seem to work either:

{
  selector: { 
    docId: "a1234"
  },
  fields: ["docId"],
  opts: {
    use_index: ["_design/assets", "search_assets"]
  }     
}

Upvotes: 0

Views: 526

Answers (1)

xpqz
xpqz

Reputation: 3737

I think you are mixing Cloudant Query (aka Mango) and Cloudant Search (Lucene behind the scenes).

The selector syntax belong to the former, whereas the index function as described looks like a Search/Lucene index.

Cloudant Search -- both how to index and how to query is well documented here.

If you prefer the newer Cloudant Query, that's documented here.

There is some overlap, and Cloudant Query's text indexes are implemented on top of Cloudant Search, to confuse matters further.

Upvotes: 0

Related Questions