Perl
Jan 2015
Commands
Accessing server information
Creating a database
Get database info
Create a document
Retrieve a document
Update document
delete a document
delete a database
Etc.
Apr 22, 2015
Mappings
Dumping and Reloading
CouchDB
Apr 22, 2015 - I installed the following:
- elasticsearch 1.5.1
- plugin elasticsearch-river-couchdb 2.5.0
NodeJS and ElasticSearch
http://daemon.co.za/2012/05/elasticsearch-5-minutes/
https://github.com/AdrianRossouw/elasticsearch-example
http://daemon.co.za/2012/05/replacing-couchdb-views-with-elasticsearch/
http://www.ripariandata.com/blog/time-to-relax-installing-couchdb-and-elasticsearch
http://www.elasticsearch.cn/guide/reference/river/couchdb.html
https://github.com/elastic/elasticsearch-river-couchdb/
sudo -u elasticsearch /usr/share/elasticsearch/bin/elasticsearch -d -p /var/run/elasticsearch.pid --default.config=/etc/elasticsearch/elasticsearch.yml --default.path.home=/usr/share/elasticsearch --default.path.logs=/var/log/elasticsearch --default.path.data=/var/lib/elasticsearch --default.path.work=/tmp/elasticsearch --default.path.conf=/etc/elasticsearch
"added a line into /etc/init.d/elasticsearch to print out the above command:"
# Start Daemon
log_daemon_msg "sudo -u $ES_USER $DAEMON $DAEMON_OPTS" # <-- Add this line
start-stop-daemon --start -b --user "$ES_USER" -c "$ES_USER" --pidfile "$PID_FILE" --exec $DAEMON -- $DAEMON_OPTS
log_end_msg $?
Searching
- http://lethain.com/full-text-search-in-couchdb-using-couchdb/
- http://www.techfreak.net/2013/11/14/a-couchdb-view-example.html
- http://stackoverflow.com/questions/5285787/full-text-search-in-couchdb
- http://sitr.us/2009/06/30/database-queries-the-couchdb-way.html
- http://blog.mattwoodward.com/2011/05/string-matching-in-couchdb-views.html
- http://wiki.apache.org/couchdb/Full_text_search?action=show&redirect=FullTextSearch
- http://www.elasticsearch.org/
- https://github.com/rnewson/couchdb-lucene
- https://github.com/elasticsearch/elasticsearch-river-couchdb
- http://stackoverflow.com/questions/4298937/couchdb-views-remove-duplicates-and-order-by-time
- http://stackoverflow.com/questions/5571459/couchdb-view-query-with-multiple-key-values
Book
http://guide.couchdb.org/draft/tour.html
https://pythonhosted.org/CouchDB/mapping.html
http://stackoverflow.com/questions/4773069/sorting-dates-in-couchdb-views
For easier searching, it's best to install Lucene
- https://github.com/rnewson/couchdb-lucene
- http://www.slideshare.net/martin.rehfeld/couchdblucene
- http://www.spaceinvade.rs/2014/07/23/CouchDB-Lucene-integration/
- http://lucene.apache.org/core/2_9_4/queryparsersyntax.html
Installed CouchDB on Oct 10, 2014.
apt-get install couchdb
It installed version 1.0.1.
Version 1.6.1 is available.
https://github.com/rnewson/couchdb-lucene
https://launchpad.net/~couchdb/+archive/ubuntu/stable
# install the ppa-finding tool
# for 12.04 release
sudo apt-get install python-software-properties -y
# for 14.04 release
sudo apt-get install software-properties-common -y
# add the ppa
sudo add-apt-repository ppa:couchdb/stable -y
# update cached list of packages
sudo apt-get update -y
# remove any existing couchdb binaries
sudo apt-get remove couchdb couchdb-bin couchdb-common -yf
# see my shiny goodness - note the version number displayed and ensure its what you expect
sudo apt-get -f install
sudo apt-get install -V couchdb
# manage via upstart
sudo stop couchdb
couchdb stop/waiting
# update /etc/couchdb/local.ini with 'bind_address=0.0.0.0' as needed
sudo start couchdb
couchdb start/running, process 17422
# check version
couchdb -V
couchdb - Apache CouchDB 1.6.1
Good. Up to date. Oct 10, 2014
old post:
http://blog.woobling.org/2009/05/why-i-dont-use-couchdb.html
Perl
http://search.cpan.org/dist/CouchDB-Client/lib/CouchDB/Client.pm
The above main module is outdated or oldish, 2009.
http://cpanratings.perl.org/dist/CouchDB-Client
"Generally, when I have a choice I prefer AnyEvent::CouchDB."
http://search.cpan.org/~beppu/AnyEvent-CouchDB- 1.31/lib/AnyEvent/CouchDB.pm - (2011)
perl -MCPAN -e 'install CouchDB::Client'
Installed above Perl module on Oct 10, 2014. It took under one minute to install, unlike the nearly 10 minutes to complete the install of the MongoDB Perl client module.
Jan 2015
- Store::CouchDB
- http://search.cpan.org/~norbu/Store-CouchDB-3.8/lib/Store/CouchDB.pm
- https://github.com/norbu09/Store-CouchDB
- https://metacpan.org/pod/Store::CouchDB
- installed on Jan 13, 2015
- had to manually download and install Types::Serialiser too. this module is used by Store::CouchDB
Commands
http://wiki.apache.org/couchdb/Complete_HTTP_API_Reference
CouchDB is API, HTTP, REST, JSON, and JavaScript driven.
in the file /etc/couchdb/local.ini
set and uncomment the lines:
port=5984
bind_address=127.0.0.1
http://en.wikipedia.org/wiki/CouchDB
Accessing server information
Reponse:
{"couchdb":"Welcome","uuid":"2c6d440df9b206a8592c4f5db6f4e38a","version":"1.6.1","vendor":{"name":"Ubuntu","version":"12.04"}}
Creating a database
Creating a database named wiki
curl -X PUT http://127.0.0.1:5984/wiki
Response:
{"ok": true}
Attempting to create a second database named wiki
curl -X PUT http://127.0.0.1:5984/wiki
Response:
{"error":"file_exists", "reason":"The database could not be created, the file already exists."}
Get database info
Retrieve information about the wiki database
curl http://127.0.0.1:5984/wiki
{"db_name":"wiki","doc_count":0,"doc_del_count":0,"update_seq":0,"purge_seq":0,"compact_running":false,"disk_size":79,"data_size":0,"instance_start_time":"1412965274017838","disk_format_version":6,"committed_update_seq":0}
Create a document
Create a document, asking CouchDB to supply a document id
curl -X POST -H "Content-Type: application/json" --data '{ "text" : "Wikipedia on CouchDB", "rating": 5 }'
http://127.0.0.1:5984/wiki
Response
{"ok":true,"id":"eadaefc9769de77b098009cfae000ef6","rev":"1-80fd6f7aeb55c83c8999b4613843af5d"}
Retrieve a document
curl http://127.0.0.1:5984/wiki/eadaefc9769de77b098009cfae000ef6
Response
{"_id":"eadaefc9769de77b098009cfae000ef6","_rev":"1-80fd6f7aeb55c83c8999b4613843af5d","text":"Wikipedia on CouchDB","rating":5}
Update document
http://wiki.apache.org/couchdb/HTTP_Document_API#PUT
curl -X PUT -H "Content-Type: application/json" --data '{ "text" : "Wikipedia on CouchDB", "rating": 0, "_rev":"1-80fd6f7aeb55c83c8999b4613843af5d"}'
http://127.0.0.1:5984/wiki/eadaefc9769de77b098009cfae000ef6
Response
{"ok":true,"id":"eadaefc9769de77b098009cfae000ef6","rev":"2-5ba469fb0677c7293baab0403c478fd2"}
delete a document
curl -X DELETE http://127.0.0.1:5984/dbname/doc_id?rev=1-b42c8ec490cdf81c5d2b1243065b9aaf
delete a database
curl -vX DELETE http://127.0.0.1:5984/dbname
Etc.
[X] http://guide.couchdb.org/draft/cookbook.html
[X] http://guide.couchdb.org/draft/views.html
http://stackoverflow.com/questions/2923063/searching-by-key-in-apache-couchdb
http://sitr.us/2009/06/30/database-queries-the-couchdb-way.html
Apr 22, 2015
curl -X PUT '127.0.0.1:9200/_river/scaupdvlp1/_meta' -d '{ "type" : "couchdb", "couchdb" : { "host" : "localhost", "port" : 5984, "db" : "scaupdvlp1", "filter" : null }, "index" : { "index" : "scaupdvlp1", "type" : "scaupdvlp1", "bulk_size" : "100", "bulk_timeout" : "10ms" } }'
returned
{"_index":"_river","_type":"scaupdvlp1","_id":"_meta","_version":1,"created":true}
http://www.elastic.co/guide/en/elasticsearch/guide/current/pagination.html
http://www.elastic.co/guide/en/elasticsearch/guide/current/empty-search.html
http://www.elastic.co/guide/en/elasticsearch/guide/current/search-lite.html
http://www.elastic.co/guide/en/elasticsearch/guide/current/query-dsl-intro.html
http://okfnlabs.org/blog/2013/07/01/elasticsearch-query-tutorial.html#curl-or-browser
https://gist.github.com/karussell/1639766
Search for 'MrX' in the 'name' field
+name:mrx
curl 'http://127.0.0.1:9200/dbname/indexname/_search?q=%2Bname%3Amrx&pretty=true'
Search for 'MrX' in the 'name' field that have a 'type' of 'author'.
+name:mrx +type:author
curl 'http://127.0.0.1:9200/dbname/indexname/_search?q=%2Bname%3Amrx+%2Btype%3Aauthor&pretty=true'
Search all fields for the term 'scarf'.
curl 'http://127.0.0.1:9200/dbname/indexname/_search?q=scarf&pretty=true'
Search the 'markup' field for the term 'scarf' for docs of type 'post' that have a status of 'public'.
+type:post +post_status:public +markup:scarf
curl 'http://127.0.0.1:9200/dbname/indexname/_search?q=%2Btype%3Apost+%2Bpost_status%3Apublic+%2Bmarkup%3Ascarf&pretty=true'
searching for exact phrase of 'looks like candy'.
curl 'http://127.0.0.1:9200/dbname/indexname/_search?q=%2Btype%3Apost+%2Bpost_status%3Apublic+%2Bmarkup%3Alooks+like+candy&pretty=true'
search for exact phrase of 'Scarf for Mom' with all lowercase text provided. search is case insensitive.
searching for exact phrase of 'looks like candy'.
curl 'http://127.0.0.1:9200/dbname/indexname/_search?q=%2Btype%3Apost+%2Bpost_status%3Apublic+%2Bmarkup%3Ascarf+for+mom&pretty=true'
The next query searches for tweets, using the following criteria:
- The
name
field containsmary
orjohn
- The
date
is greater than2014-09-10
- The
_all
field contains either of the wordsaggregations
orgeo
+name:(mary john) +date:>2014-09-10 +(aggregations geo)
As a properly encoded query string, this looks like the slightly less readable result:
?q=%2Bname%3A(mary+john)+%2Bdate%3A%3E2014-09-10+%2B(aggregations+geo)
curl -XGET http://127.0.0.1:9200/scaupdvlp1/scaupdvlp1/_search -d '{"query" : { "term" : {"markup" : "scarf" }} }'
or
curl -XGET http://127.0.0.1:9200/scaupdvlp1/scaupdvlp1/_search -d '{"query" : { "match" : {"markup" : "scarf" }} }'
Mappings
http://gauth.fr/2012/08/exact-search-with-elasticsearch/
Dumping and Reloading
http://stackoverflow.com/questions/11639534/couchdb-dump-to-file-and-load-from-file
https://github.com/danielebailo/couchdb-dump
http://wiki.apache.org/couchdb/HTTP_Bulk_Document_API
curl -X GET <a href="http://localhost:5984/<DATABASE_NAME>/_all_docs?include_docs=true">http://localhost:5984/<DATABASE_NAME>/_all_docs?include_docs=true</a> > FILE.txt
#database - #nosql - #json
From JR's : articles
764 words - 10804 chars
- 4 min read
created on
updated on
- #
source
- versions