Querying views using N1QL

Hello,
I see in some documentation that “MapReduce View Indexes are accessed from both the
View API and the N1QL query language” but I didn’t find any example of querying view using N1QL.

Is this possible?

Another point,for views update, there is this viewUpdateDaemon which do the update automatcally.
Is there any similar process to auto update GSI and if not, why this difference between updating views index and GSI index?

Thanks

To query a view using N1QL, you need create the view in N1QL, using:

CREATE INDEX idx ON bucket1( ... ) USING VIEW;

Thanks geraldess,

And for the second point please,what is the difference between updating a GSI and a view?

For N1QL indexes, you will update neither GSI nor view. They will both be updated automatically as your documents are added, updated, and deleted.

Thanks geradless,
Just I mean the difference in updating index when using view api to query mapreduce views and when using views created via “CREATE INDEX idx ON bucket1( … ) USING VIEW;”

I have done tehse two tests:

  • create view via "CREATE INDEX idx ON default( name) USING VIEW
    than i created added new document and executed the following query:
    select count(*) FROM default WHERE name=‘test’ ;
    I got the correct total

  • create a map-reduce view
    I have added a new document and used View api to query it
    The new added document wasn’t returned only the second time (default stale bahaviour as it is set to:update_after)

So why two differents update mechanisms for view ?
Thanks

The N1QL view behavior is not guaranteed unless you use scan_consistency = REQUEST_PLUS.

Hi…
I have created one checklistdrmap view using below map() function.

Map:
function (doc, meta) {
if (doc.tree && meta.id)
{
for (i=0; i < doc.tree.length; i++)
{
var doc1 = doc.tree[i];
var path = “tree[”+i+"]";
walk(doc1,path);
}
}
function walk(doc,path2){
if(doc.children.length > 0 )
{
emit(doc.id,{“id”:meta.id,“docid”:doc.id,“description”:doc.description,
“isDisclosureRequirement”:doc.isDisclosureRequirement,
“path”:path2});
for (var j=0; j < doc.children.length; j++)
{
var path1 = path2 + “.children[”+j+"]";
walk(doc.children[j],path1);
}
}
else{
emit(doc.id,{“id”:meta.id,“docid”:doc.id,“description”:doc.description,
“isDisclosureRequirement”:doc.isDisclosureRequirement,“path”:path2});
}
}
}

the result is showing like below while passing key=“100305” :
{
“id”: “0bf151d5-f30b-4b56-908c-3bec4fbacf1c”,
“docid”: “100305”,
“description”: “Sample Description”,
“isDisclosureRequirement”: false,
“path”: “tree[0]”
}

But, If I need to pass two parameters like key=“100305” and id=“0bf151d5-f30b-4b56-908c-3bec4fbacf1c”,
Could you please help me where I can pass these two values ?