How to get average size of document_id in couchbase


#1

Hi,

I would like to know, how to get average size of document IDs in couchbase. Is there any REST API for that?

Thanks in advance.


#2

With Couchbase 4.x, you can use the following N1QL query.

SELECT AVG( LENGTH( META().id ) ) AS avg
FROM my_bucket;


#3

Hi @geraldss Thanks for reply. Is there any REST API to get the same like /pools/default/buckets/stats.


#4

There is a N1QL REST API, but it is not yet in the documentation: https://docs.google.com/document/d/1Uyv4t06DNGq7TxJjGI_T_MbbEYf8Er-imC7yzTY0uZw/edit#heading=h.lfqenz86v2rl

You can send the REST request to port 8093 on any node running the Query service. You need to pass a statement parameter containing your N1QL statement.


#5

@geraldss Thanks for sharing link. Its really helpful. :slight_smile:


#6

@ch.harish1271 why don’t you just execute this statement through the SDK of your favourite language? That’s the recommended way to access it :slight_smile:


#7

@daschl We have some scripts wich developed by using REST API. So to add more features in that , we prefer to use API instead of SDK.


#8

@geraldss @daschl We are using couchbase 3.x version. In that N1QL is not supported. How can I get the Key size details?


#9

You should upgrade to 4.x.


#10

@geraldss We will upgrade to 4.x soon. Is there any possible way to find out average size in 3.x?


#11

You can use a MapReduce view to calculate the total length of all the keys. After that, you can divide by the number of entries in your bucket.


#12

@geraldss Thanks for reply. I am new to map reduce in couchbase. Can you please share any good references to get this.


#13

Hi @ch.harish1271, I don’t have any pointers besides the product documentation.

If you will be upgrading soon, you should decide whether to learn the MapReduce views or wait for your upgrade.