Hi,
I’m using Couchbase quite long for my caching which works simply by set() and get() the id of a document and it’s data formatted in Json.
Now I wondered if I cimply can (I cannot make it clear out of the docs) if I can query for something that is in my Json data all over the documents and get back the full Json response of that document.
I cannot find something like a “howto” so I need to as becaus the docs are pretty good but I don’t get the clue out of it.
I hope someone can help me out!
Thanks,
Matt
vsr1
July 2, 2018, 12:43pm
2
1 Like
OK, that looks a little bit better, but what I don’t get is, do I need views for my bucket ? I try to implement this in PHP.
vsr1
July 2, 2018, 1:13pm
4
When Cluster is configured bring up these services
Data
Index
Query
Then Create appropriate index (Primary or Secondary Indexes) and issue queries.
No views required.
Useful information available here https://blog.couchbase.com/a-guide-to-n1ql-features-in-couchbase-5-5-special-edition/
1 Like
Thanks, very good documents indeed. As I’m checking the webgui I cannot set mem for Queries but that might be because you never know how large the result will be. But creating an index is not possible there, is that true ?
vsr1
July 2, 2018, 1:54pm
6
You can’t set memory quotas for Query Service.
(Query Workbench) Query Tab in Web Console allows you create indexes and issue queries. Type the SQL statement and Execute.
https://blog.couchbase.com/a-tour-of-the-new-couchbase-web-console/
1 Like
Because of your help so far I’m a little but further. I can do a select * from bucketname; and get the result with the following index:
CREATE INDEX geoCode ON `geoPoints`(code);
Where my Document in my bucket is:
{"code":"Ok","waypoints":[{"hint":"yHYJgNN4CYAQAAAAKAAAAHcAAACaAAAAW2k1QTG_0EFDbZ9CS6huQhAAAAAoAAAAdwAAAJoAAABSBQAAPfVUAKZtGAMJ9lQAGGwYAwMAj",....
Where the following gives me an empty result:
select * from geoPoints where code = "Ok"
I let the query explain but don’t see anything strange in the output there.
What am I’m missing here ? I’m on the community 5.1.1 version.
vsr1
July 3, 2018, 12:28pm
8
It should work. Post the EXPLAIN output
Here you go:
{
“plan”: {
“#operator ”: “Sequence”,
“~children”: [
{
“#operator ”: “PrimaryScan”,
“index”: “geoPoints”,
“keyspace”: “geoPoint”,
“namespace”: “default”,
“using”: “gsi”
},
{
“#operator ”: “Fetch”,
“keyspace”: “geoPoint”,
“namespace”: “default”
},
{
“#operator ”: “Parallel”,
“~child”: {
“#operator ”: “Sequence”,
“~children”: [
{
“#operator ”: “Filter”,
“condition”: “((geoPoint
.Code
) = “ok”)”
},
{
“#operator ”: “InitialProject”,
“result_terms”: [
{
“expr”: “self”,
“star”: true
}
]
},
{
“#operator ”: “FinalProject”
}
]
}
}
]
},
“text”: “select * from geoPoints where Code=“ok”;”
}
vsr1
July 3, 2018, 12:39pm
10
YamakasY:
{“code”:“Ok”,“waypoints”:[{“hint”:“yHYJgNN4CYAQAAAAKAAAAHcAAACaAAAAW2k1QTG_0EFDbZ9CS6huQhAAAAAoAAAAdwAAAJoAAABSBQAAPfVUAKZtGAMJ9lQAGGwYAwMAj”,…
“text”: “select * from geoPoints where Code=“ok”;”
Make sure the field names and values are case sensitive.
Example: Document has “code”: “Ok” i.e lower case c and Upper case O
But query has Upper case C and lower case o
Try this.
SELECT * FROM geoPoints
WHERE code="Ok";
Sorry that was a typo indeed as I was testing case sensitive, same issue there. Do you want to see that explain as well ?
OK, here you go again:
{
“plan”: {
“#operator ”: “Sequence”,
“~children”: [
{
“#operator ”: “PrimaryScan”,
“index”: “geoPoints”,
“keyspace”: “geoPoints”,
“namespace”: “default”,
“using”: “gsi”
},
{
“#operator ”: “Fetch”,
“keyspace”: “geoPoints”,
“namespace”: “default”
},
{
“#operator ”: “Parallel”,
“~child”: {
“#operator ”: “Sequence”,
“~children”: [
{
“#operator ”: “Filter”,
“condition”: “((geoPoints
.code
) = “Ok”)”
},
{
“#operator ”: “InitialProject”,
“result_terms”: [
{
“expr”: “self”,
“star”: true
}
]
},
{
“#operator ”: “FinalProject”
}
]
}
}
]
},
“text”: “SELECT * FROM geoPoints WHERE code=“Ok”;”
}
vsr1
July 3, 2018, 12:56pm
14
Plan seems right can get output of
SELECT * FROM geoPoints LIMIT 1;
1 Like
Yes that works, I get one result back.
[
{
"geoPoints": "{\"code\":\"Ok\",\"waypoints\":[{\"hint\":\"yHYJgNN4CYAQAAAAKAAAAHcAAACaAAAAW2k1QTG_0EFDbZ9CS6huQhAAAAAoAAAAdwAAAJoAAABSBQAAPfVUAKZtGAMJ9lQAGGwYAwMAjwRk ...
}
]
Is there some depth issue ? I cut of the rest as it’s quite some data The beginning/end should be needed to see.
vsr1
July 3, 2018, 1:04pm
18
YamakasY:
geoPoint_cache
Where did u get geoPoint_cache? Can u paste the query? or Paste complete highrarchy of document that includes root to code path only.
Also try this. nested fields in object needs to be referenced with path each object separated with .
SELECT * FROM geoPoints
WHERE geoPoint_cache.code="Ok";
Sorry, I was testing 2 different buckets with different indexes to see where it goes wrong. You can keep the geoPoints but I also tried nested onject with the . same issue, empty result.
vsr1
July 3, 2018, 1:16pm
20
Please Post the document where you are trying.
You can try the following simple one and see if it works.
INSERT INTO default VALUES ("k101",{"code":"Ok","waypoints":[]});
CREATE INDEX ix11 ON default(code);
SELECT * FROM default WHERE code = "Ok";
1 Like