Skip to content

Instantly share code, notes, and snippets.

@pzol
Last active December 14, 2015 02:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pzol/5015623 to your computer and use it in GitHub Desktop.
Save pzol/5015623 to your computer and use it in GitHub Desktop.
Elastic Search Experiments

Create a mongo replicaset

tutorial

rsconf = {
           _id: "rs0",
           members: [
                      {
                       _id: 0,
                       host: "localhost:27017"
                      }
                    ]
         }
rs.initiate( rsconf )

Elasticsearch

Install

/usr/local/opt/elasticsearch/bin/plugin -install elasticsearch/elasticsearch-lang-javascript/1.2.0
/usr/local/opt/elasticsearch/bin/plugin -install elasticsearch/elasticsearch-mapper-attachments/1.6.0
/usr/local/opt/elasticsearch/bin/plugin -url https://github.com/downloads/richardwilly98/elasticsearch-river-mongodb/elasticsearch-river-mongodb-1.6.1.zip -install river-mongodb

Start

elasticsearch -f -D es.config=/usr/local/opt/elasticsearch/config/elasticsearch.yml

Create index

curl -XDELETE 'http://localhost:9200/bms/'
curl -XPUT localhost:9200/bms -d '{
  "index.mapper.dynamic": false
}'

Setup mapping

curl -XPUT 'http://localhost:9200/bms/bookings/_mapping' -d '
{
    "bookings" : {
        "properties" : {
          ref_anixe: { type: "string", store: "yes" },
          ref_castor: { type: "string", store: "yes" },
          ref_customer: { type: "string", store: "yes" },
          status: { type: "string", store: "yes" },
          billing: { type: "object", store: false, enabled: false },
          cancellation_fees : { enabled: false },
          fares: { type: "object", store: false, enabled: false },
          segments: { type: "object", store: false, enabled: false },
          services: { type: "object", store: false, enabled: false },
          cancellation_fees: { type: "object", store: false, enabled: false },
          passengers: { type: "object", store: false, enabled: false }
        }
    }
}
'

Initiate River

curl -XPUT 'http://localhost:9200/_river/bms/_meta' -d '{
    "type": "mongodb",
    "mongodb": {
        "db": "bms",
        "collection": "bookings",
        "script": "ctx.document = { ref_anixe: ctx.document.ref_anixe, status: ctx.document.status}"
    },
    "index": {
        "name": "bms",
        "type": "bookings"
    }
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment