Skip to content

Instantly share code, notes, and snippets.

@pacoguzman
Created July 4, 2011 06:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pacoguzman/1062993 to your computer and use it in GitHub Desktop.
Save pacoguzman/1062993 to your computer and use it in GitHub Desktop.
ElasticSearch and Couchdb River
# Create design documents with the filters
curl -vX PUT 'http://127.0.0.1:5984/couchdb_myapp_development/_design/Product' -d '{
"_id": "_design/Product",
"language": "javascript",
"filters": {
"product": "function(doc, req) { return doc['type'] == 'Product'; }"
}
}'
curl -vX PUT 'http://127.0.0.1:5984/couchdb_myapp_development/_design/Person' -d '{
"_id": "_design/Person",
"language": "javascript",
"filters": {
"person": "function(doc, req) { return doc['type'] == 'Person'; }"
}
}'
# Store one document
curl -X POST 'http://127.0.0.1:5984/couchdb_myapp_development/' -d '{
"_id": "124a10f3b56882607c8f3c89cd053c4c",
"type": "Product",
"name": "Time Capsule",
"description": "La Time Capsule es una estación base Airport completa con un disco duro integrado con la que podrás hacer copias de seguridad de manera inalámbrica y crear una red Wi-Fi con un solo dispositivo."
}'
# Execute a search query
curl -X POST "http://localhost:9200/products/product/_search?pretty=true" -d '{
"query" : {
"query_string" : {
"query" : "inalámbrica"
}
}
}' =>
{
"took" : 29,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 0.033902764,
"hits" : [ {
"_index" : "products",
"_type" : "product",
"_id" : "124a10f3b56882607c8f3c89cd053c4c",
"_score" : 0.033902764, "_source" : {"_rev":"1-34cacc5258bbca9b83bef738a08f155d","_id":"124a10f3b56882607c8f3c89cd053c4c","description":"La Time Capsule es una estación base Airport completa con un disco duro integrado con la que podrás hacer copias de seguridad de manera inalámbrica y crear una red Wi-Fi con un solo dispositivo.","name":"Time Capsule","type":"Product"}
} ]
}
# Create the river for each type of document
curl -XPUT 'http://localhost:9200/_river/products/_meta' -d '{
"type" : "couchdb",
"couchdb" : {
"host" : "localhost",
"port" : 5984,
"db" : "couchdb_myapp_development",
"filter" : "Product/product"
},
"index" : {
"index" : "products",
"type" : "product"
}
}'
curl -XPUT 'http://localhost:9200/_river/people/_meta' -d '{
"type" : "couchdb",
"couchdb" : {
"host" : "localhost",
"port" : 5984,
"db" : "couchdb_myapp_development",
"filter" : "Person/person"
},
"index" : {
"index" : "people",
"type" : "person"
}
}'
# INSTALL ElasticSearch
curl -k -L -# -o elasticsearch-0.16.2.tar.gz \
"http://github.com/downloads/elasticsearch/elasticsearch/elasticsearch-0.16.2.tar.gz"
tar -zxf elasticsearch-0.16.2.tar.gz
rm -f elasticsearch-0.16.2.tar.gz
# INSTALL Couchdb River
./elasticsearch-0.16.2/bin/plugin -install river-couchdb
# Start ElasticSearch
./elasticsearch-0.16.2/bin/elasticsearch -p #{destination_root}/tmp/pids/elasticsearch.pid
# Couchdb App Database (couchdb_myapp_development)
curl -vX PUT 'http://127.0.0.1:5984/couchdb_myapp_development'
# Create river index
curl -XPUT 'http://localhost:9200/_river/couchdb_myapp_development_river/_meta' -d '{
"type" : "couchdb",
"couchdb" : {
"host" : "localhost",
"port" : 5984,
"db" : "couchdb_myapp_development",
"filter" : null
}
}'
@slorber
Copy link

slorber commented Jun 6, 2012

thanks! really helps me

@pacoguzman
Copy link
Author

Glad to help @slorber

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment