From e4bf004c746db88e2eae5576cf25a9eefdaade3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n=20Holp?= Date: Fri, 23 Oct 2020 07:41:12 +0000 Subject: [PATCH] Upload files to 'pages/students/2016/jan_holp/dp2021/zdrojove_subory' --- .../dp2021/zdrojove_subory/cassandra.js | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 pages/students/2016/jan_holp/dp2021/zdrojove_subory/cassandra.js diff --git a/pages/students/2016/jan_holp/dp2021/zdrojove_subory/cassandra.js b/pages/students/2016/jan_holp/dp2021/zdrojove_subory/cassandra.js new file mode 100644 index 00000000..43e0157e --- /dev/null +++ b/pages/students/2016/jan_holp/dp2021/zdrojove_subory/cassandra.js @@ -0,0 +1,105 @@ +//Jan Holp, DP 2021 + + +//client1 = cassandra +//client2 = elasticsearch +//----------------------------------------------------------------- + +//require the Elasticsearch librray +const elasticsearch = require('elasticsearch'); +const client2 = new elasticsearch.Client({ + hosts: [ 'localhost:9200'] +}); +client2.ping({ + requestTimeout: 30000, + }, function(error) { + // at this point, eastic search is down, please check your Elasticsearch service + if (error) { + console.error('Elasticsearch cluster is down!'); + } else { + console.log('Everything is ok'); + } + }); + +//create new index skweb2 +client2.indices.create({ + index: 'skweb2' +}, function(error, response, status) { + if (error) { + console.log(error); + } else { + console.log("created a new index", response); + } +}); + +const cassandra = require('cassandra-driver'); +const client1 = new cassandra.Client({ contactPoints: ['localhost:9042'], localDataCenter: 'datacenter1', keyspace: 'websucker' }); +const query = 'SELECT title FROM websucker.content WHERE body_size > 0 ALLOW FILTERING'; +client1.execute(query) + .then(result => console.log(result)),function(error) { + if(error){ + console.error('Something is wrong!'); + console.log(error); + } else{ + console.log('Everything is ok'); + } + }; + +/* +async function indexData() { + + var i = 0; + const query = 'SELECT title FROM websucker.content WHERE body_size > 0 ALLOW FILTERING'; + client1.execute(query) + .then((result) => { + try { + //for ( i=0; i<15;i++){ + console.log('%s', result.row[0].title) + //} + } catch (query) { + if (query instanceof SyntaxError) { + console.log( "Neplatne query" ); + } + } + + + + }); + + + } + +/* + +//indexing method +const bulkIndex = function bulkIndex(index, type, data) { + let bulkBody = []; + id = 1; +const errorCount = 0; + data.forEach(item => { + bulkBody.push({ + index: { + _index: index, + _type: type, + _id : id++, + } + }); + bulkBody.push(item); + }); + console.log(bulkBody); + client.bulk({body: bulkBody}) + .then(response => { + + response.items.forEach(item => { + if (item.index && item.index.error) { + console.log(++errorCount, item.index.error); + } + }); + console.log( + `Successfully indexed ${data.length - errorCount} + out of ${data.length} items` + ); + }) + .catch(console.err); +}; +*/ \ No newline at end of file