Ejemplo n.º 1
0
    def get_server_docs_with_prefix(self, bucket, prefix):
        """
        Returns server doc ids matching a prefix (ex. '_sync:rev:')
        """

        b = Bucket("couchbase://{}/{}".format(self.host, bucket),
                   password='******')
        b_manager = b.bucket_manager()
        b_manager.n1ql_index_create_primary(ignore_exists=True)
        found_ids = []
        for row in b.n1ql_query("SELECT meta(`{}`) FROM `{}`".format(
                bucket, bucket)):
            log_info(row)
            if row["$1"]["id"].startswith(prefix):
                found_ids.append(row["$1"]["id"])

        return found_ids
Ejemplo n.º 2
0
    def delete_couchbase_server_cached_rev_bodies(self, bucket):
        """
        Deletes docs that follow the below format
        _sync:rev:att_doc:34:1-e7fa9a5e6bb25f7a40f36297247ca93e
        """

        b = Bucket("couchbase://{}/{}".format(self.host, bucket),
                   password='******')
        b_manager = b.bucket_manager()
        b_manager.n1ql_index_create_primary(ignore_exists=True)
        cached_rev_doc_ids = []
        for row in b.n1ql_query("SELECT meta(`{}`) FROM `{}`".format(
                bucket, bucket)):
            if row["$1"]["id"].startswith("_sync:rev"):
                cached_rev_doc_ids.append(row["$1"]["id"])

        log_info("Found temp rev docs: {}".format(cached_rev_doc_ids))
        for doc_id in cached_rev_doc_ids:
            log_debug("Removing: {}".format(doc_id))
            b.remove(doc_id)
Ejemplo n.º 3
0
def ensure_create_type_index(bucket: Bucket):
    manager = bucket.bucket_manager()
    return manager.n1ql_index_create("idx_type",
                                     ignore_exists=True,
                                     fields=["type"])
Ejemplo n.º 4
0
def ensure_create_primary_index(bucket: Bucket):
    manager = bucket.bucket_manager()
    return manager.n1ql_index_create_primary(ignore_exists=True)
Ejemplo n.º 5
0
    fts_json = open(settings.FTS_INDEX_FILE, 'r')
    url = "http://{0}:8094/api/index/{1}".format(node, fts_index_name)
    payload = json.load(fts_json)
    headers = {'content-type': 'appllication.json'}
    x = requests.put(url,
                     data=json.dumps(payload),
                     headers=headers,
                     timeout=timeout,
                     auth=HTTPBasicAuth(admin_user, admin_password))
    if x.status_code == 200:
        print("Indexes created successfully!")
    else:
        print(
            "!!! Error creating indexes:\n{0}\nExecute cleanup.py and try again"
            .format(x.text))


if __name__ == '__main__':
    sdk_admin = Admin(admin_user, admin_password, host=node)
    admin_create_bucket(sdk_admin)
    # Workaround wait_ready is not enough...
    time.sleep(timeout)
    sdk_client = Bucket('couchbase://{0}/{1}'.format(node, bucket_name),
                        username=user,
                        password=password)
    sdk_client.timeout = timeout
    bucket_manager = sdk_client.bucket_manager()
    add_stocks(sdk_client)
    add_indexes(bucket_manager)
    add_fts_indexes()
Ejemplo n.º 6
0
#!/usr/bin/env python

from couchbase.bucket import Bucket

cb = Bucket('couchbase://localhost/default')
manager = cb.bucket_manager()
manager.n1ql_index_create_primary(ignore_exists=True)
Ejemplo n.º 7
0
    'views': {
        'top_keywords': {
            'map':
            """
            function(doc) {
                if (typeof doc === 'number') {
                    emit(doc, null);
                }
            }
            """
        }
    }
}

if options.create_design:
    bm = c.bucket_manager()
    bm.design_create('search_keywords', DESIGN, use_devmode=False, syncwait=5)

NOUNS = ['cow', 'cat', 'dog', 'computer', 'WMD']
ADJECTIVES = ['happy', 'sad', 'thoughtful', 'extroverted']

kv = {}

for x in range(options.number_of_terms):
    n = random.choice(NOUNS)
    a = random.choice(ADJECTIVES)
    kv[" ".join([a, n])] = random.randint(1, 100000)

c.upsert_multi(kv)

vret = c.query('search_keywords',