drakerian / loopback-connector-elastic-search

Strongloop Loopback connector for Elasticsearch
MIT License
33 stars 86 forks source link

loopback-connector-elastic-search

Basic Elasticsearch datasource connector for Loopback.

Setting up Elasticsearch

Populate for demo Elasticsearch

Run in terminal:

curl -XPUT http://localhost:9200/shakespeare -d '{
    "mappings" : {
        "_default_" : {
            "properties" : {
                "speaker" : {"type": "string", "index" : "not_analyzed" },
                "play_name" : {"type": "string", "index" : "not_analyzed" },
                "line_id" : { "type" : "integer" },
                "speech_number" : { "type" : "integer" }
            }
        }
    }
}';

Import data example to Elasticsearch:

cd examples/data
curl -XPUT localhost:9200/_bulk --data-binary @shakespeare.json

Setting up Loopback

Install StrongLoop command line interface:

npm install -g strong-cli

Create project:

slc loopback:loopback
set project path and name

Attach datasource (see /server/datasources.json):

slc loopback:datasource test-elastic
select loopback-connector-elastic

Create model (see /examples/entry.json):

slc loopback:model entry

Install connector from NPM

npm install loopback-connector-elastic-search --save

Configuring elastic connector

Edit datasources.json and set:

[ConnectorEntry] : {
    "host": [127.0.0.1],
    "port": [9200],
    "name": [Name],
    "connector": "elastic-search",
    ...
    "log": "trace",
    "defaultSize": [Rows],
    "index": [IndexName],
    "type": [TypeName]
}

Required:

Optional:

Run example

Goto to examples folder and run:

npm install

Goto server folder and run:

node server.js

Open browse, and set in URL:

http://localhost:3000/explorer

To test a specific filter in GET method, use for example:

{"q" : "friends, romans, countrymen"}

Release notes