Git Product home page Git Product logo

couch_es's Introduction

couch_es

couch_es is an elasticsearch helper for CouchDB familly helper. Compatible with Apache CouchDB, BigCouch and Refuge.

While Elasticsearch provides the system of river it imply you manually set the river in it. Also you don't have an easy way to query elasticsearch using the CouchDB rest API like you could do with couchdb lucene or cloudant search (proprietary).

This helper allows you to:

  • index in real time databases in elastic search
  • search directly data using the CouchDB search api.
  • access to the _percolator api.

Installing with CouchDB

To install on last trunk of couchdb you just have to run the following command line:

$ make
$ make install
==> ibrowse (get-deps)
==> couch_es (get-deps)
==> ibrowse (compile)
==> couch_es (compile)

couch_es has been installed in /Users/benoitc/misc/couchdb/lib/couchdb/erlang/lib/couch_es
To launch it run the commandline:

ERL_CFLAGS="-pa /path/to/lib/couchdb/erlang/lib/couch_es" couchdb -a /path/to/etc/couchdb/couch_es.ini

Note: you need couch-config available in your script.

Installation with CouchDB 1.1x should be done manually. To compile it do the following

 $ export COUCHDB_SRC=/path/to/sources/src/couchdb
 $ erlc -I $COUCHDB_SRC *.erl

Then launch CouchDB :

$  ERL_FLAGS="-pa /path/to/couch_es" -a /path/to/couch_es.ini

Installing with bigcouch

Installing with bigcouch is easy. First clone bigcouch on your disk:

$ git clone git://github.com/refuge/bigcouch.git

And do the usual bigcouch installation process.

Test it:

Create a db with one doc.

$ curl -XPUT "localhost:5984/testdb"
$ curl -XPOST "localhost:5984/testdb" -d'{"test": 1}' -H"Content-Type: application/json"

Test to search on a db:

$ curl -XGET "localhost:5984/testdb/_search?q=test:1&pretty=true"

{
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 1,
    "max_score" : 1.0,
    "hits" : [ {
      "_index" : "testdb",
      "_type" : "testdb",
      "_id" : "64c9d5c574c9eb8853d07e4b0c000d9a",
      "_score" : 1.0, "_source" : {"_rev":"1-ea7a185b492abc69a6c8e0358d244a98","_id":"64c9d5c574c9eb8853d07e4b0c000d9a","test":1}
    } ]
  }
}

Search globally :

$ curl -XGET "localhost:5984/_search?q=test:1"

Multi db:

$ curl -XPUT "localhost:5984/testdb1"
$ curl -XPOST "localhost:5984/testdb1" -d'{"test": 1}' -H"Content-Type: application/json"
$ curl -XGET "localhost:5984/_search?q=test:1&pretty=true"
{
  "took" : 11,
  "timed_out" : false,
  "_shards" : {
    "total" : 21,
    "successful" : 21,
    "failed" : 0
  },
  "hits" : {
    "total" : 2,
    "max_score" : 1.0,
    "hits" : [ {
      "_index" : "testdb",
      "_type" : "testdb",
      "_id" : "64c9d5c574c9eb8853d07e4b0c000d9a",
      "_score" : 1.0, "_source" : {"_rev":"1-ea7a185b492abc69a6c8e0358d244a98","_id":"64c9d5c574c9eb8853d07e4b0c000d9a","test":1}
    }, {
      "_index" : "testdb1",
      "_type" : "testdb1",
      "_id" : "64c9d5c574c9eb8853d07e4b0c000e00",
      "_score" : 1.0, "_source" : {"_rev":"1-ea7a185b492abc69a6c8e0358d244a98","_id":"64c9d5c574c9eb8853d07e4b0c000e00","test":1}
    } ]
  }
} 

Or specify the db you want to search in:


$ curl -XGET "localhost:5984/_search/testdb,testdb1?q=test:1&pretty=true"
{
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 10,
    "successful" : 10,
    "failed" : 0
  },
  "hits" : {
    "total" : 2,
    "max_score" : 1.0,
    "hits" : [ {
      "_index" : "testdb",
      "_type" : "testdb",
      "_id" : "64c9d5c574c9eb8853d07e4b0c000d9a",
      "_score" : 1.0, "_source" : {"_rev":"1-ea7a185b492abc69a6c8e0358d244a98","_id":"64c9d5c574c9eb8853d07e4b0c000d9a","test":1}
    }, {
      "_index" : "testdb1",
      "_type" : "testdb1",
      "_id" : "64c9d5c574c9eb8853d07e4b0c000e00",
      "_score" : 1.0, "_source" : {"_rev":"1-ea7a185b492abc69a6c8e0358d244a98","_id":"64c9d5c574c9eb8853d07e4b0c000e00","test":1}
    } ]
  }
}

Configuration

[couch_es]
; backend to use (couchdb or bigcouch)
;backend = couchdb
; ip:host of elasticsearch
;localhost:9200
; couchdb publicinfo where elasticsearch will index
;public_host = localhost
;public_port = 5984
; number doc to index in the same time
;bulk_size = 100
; time before elasticsearch watch changes
;bulk_timeout = 10
; credentials
;username = 
;password = 
; nb tasks to run in the same time to synchronize couch & es
;concurrency = 10
; enable couch_es : yes  or no
;enable = yes

couch_es's People

Contributors

benoitc avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

refuge-attic

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.