Couchbase get buckets and views - couchbase

I just started Couchbase.
I would like to find a way to query couchbase to get all buckets like
Select * from tab;
USE <DB NAME>
and retrieve all views as they are faster to pull the data from N1Q1.

select name from system:keyspaces;
Gives all the buckets. For view definitions you need to use #Matthew Groves suggestions.

You can get a list of buckets with N1QL: SELECT r.name FROM system:keyspaces r;
There is no way that I know of to query for a list views with N1QL itself.
You can use the REST API:
To get a list of design docs (which contain views): check out GET /pools/default/buckets/<bucket.name>/ddocs
For more details, check out the documentation:
Getting Views Information
System Keyspaces

Related

MySQL ORDER BY FIELD equivalent in Redis search

How do I accomplish this custom sort by field feature available in MySQL in Redis search?
select * from product ORDER BY FIELD(id,3,2,1,4)
For some business reason, I need to enforce custom orders.
There is not equivalent of the FIELD function in RediSearch.
With FT.SEARCH / SORTBY you can sort results using a field.
In your hash, you may create a new field (NUMERIC SORTABLE) holding a value that will be used to sort the result. Of course, that would work only if you don't want need to specify a different order on each query.
Second option: This could be handled by using FT.AGGREGATE with an appropriate function. You may have a look at the existing function and see if one could be used for that. IF the function does not exist, you may do a feature request.
A third option is to implement your own scoring function using the extension API (but it may be over engineering ...)

I need a Query in SQL

I have this output for this search, but now i need to have another output that selecting according to all the best provider(NOME_PRESTADOR) for each service area(AREA_TRAB)
So, for example, to canalizador, the best provider is Arlindo Rui so i want to show just Arlindo Rui not Arlindo Rui and Bárbara Raquel, the some to the other areas.
Translating your table names would be helpful
Anyway, you're trying to select the best worker of each category from what I guess
Create a view using the query you posted, and then try something like this:
mysql SELECT best of each category in a single table
It's essentially the same problem

How to Create simple View or query subdocument

I read the docs - but can't seem to get my head around this ( I'm a SQL guy )
1) I loaded a json file in using CBdocloader
[
{
"ID": "9e78f4a6-4061-48aa-8154-0b738d93461b",
"More fields": ""
}
]
2) There is now an object in my bucket calles values100 ( that was the name of the file ) .
3) How to I access the data in this object in the bucket that I imported through a query or view?
Select * from mybucket returns 1 result that has all the rows I loaded - but I really want to query that data in that bucket? Should I create a view? Should I query a View? My Question is #3 but I am confused..
I believe there are a couple of things going on:
a. cbdocloader expects that each document is contained in a separate file. The behavior desired indicates that each document should instead be its own file, rather than one single document on Couchbase. The tool will then create multiple couchbase documents which can be indexed. I'm not sure there is a way to split out the text file using the tool; you may have to write a script to do it for you.
b. Couchbase is intended to be a document database, not a SQL database. As such, the way you would access a document in a majority of the cases is via the document id, which should have some significance to your application. This is not to say you can't look up the document id in an index, but you may find a SQL database to work better if you plan to do a lot of complex queries. If you need help on creating an index, please post a new question.

Couchbase view on multiple columns with WHERE and ORDER BY clause as in SQL

I am new to Couchbase noSql database.
I am trying to create a view, i want this view should give result as below SQL query.
SELECT * FROM Employee e WHERE e.name = "DESM%" AND e.salary < 1000 ORDER BY e.id desc
Any suggestion is very appreciated.
If you look at existing beer samples in Couchbase (it comes with it), you will find views defined there. In admin console you can run a view. Notice when you run a view you can provide filtering criteria and sort order for the result...that might be an equivalent for your SQL like functionality. Read more on Views and Indexes
yet another option is to use Couchbase v3 that comes with its own N1QL query language that can serve as another alternative. You can try it out online here.

Solr index multiple tables from MySQL

I have following mysql tables
1. user(user_id,email)
2. tweets(tweet_id,user_id,tweet)
3. tags(tag_id,tag)
4. tweets_tags(tweet_id,tag_id)
I want to show current user's tweets under "My Tweets" Tab in application. I want to get following data from Solr
user_id
email
tweet where user_id=x
tags where tweet_id=xx
How to index those mysql table on Solr? I only what to know the code of schema.xml and data-config.xml for Full/Delta import.
Note : I am not asking about MySQL connector etc, I have done already.
The use case you've described doesn't seem to justify using solr. You would just make sure you have proper keys and indexes and do it in mysql directly.
If for some reason you MUST use solr, you could probably prepare all the data and feed it to solr in a tag/tweet/user structure like this
user1 - tweet1 - tag1
user1 - tweet1 - tag2
user1 - tweet2 - tag1
and so on.
Then from solr you query by user, and then sort and group by tweet and then tag.
However I must state again that the solution I just described is implemented much safer with a higher confidence on the result by using plain sql.
Should you provide more details on your desired outcome, I'd be happy to suggest the database structure along with the necessary foreign keys and indexes and the queries you need to get your data out.
If you are using DIH (dataimporterhandler), I guess that link should be the solution for you:
Import with sub entities
If you have problem with writing the exact configurations, please let me know, I can assist you.