Basic Elasticsearch datasource connector for Loopback.
This version can have multiple index and it will use Model name like Index.
-
Download and install Elasticsearch
-
Goto /elasticsearch-path/bin$ and execute ./elasticsearch
-
Optional install head plugin
-
Open browser and goto default url: http://localhost:9200/
-
To use head plugin goto: http://localhost:9200/_plugin/head/
-
If all is ok then the result is some this:
{ status: 200, name: "Arno Stark", version: { number: "1.3.2", build_hash: "dee175dbe2f254f3f26992f5d7591939aaefd12f", build_timestamp: "2014-08-13T14:29:30Z", build_snapshot: false, lucene_version: "4.9" }, tagline: "You Know, for Search" }
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
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
npm install loopback-connector-elastic --save
Edit datasources.json and set:
[ConnectorEntry] : {
"host": [127.0.0.1],
"port": [9200],
"name": [Name],
"connector": "elastic-search",
...
"log": "trace",
"defaultSize": [Rows],
"index": [IndexName]
}
- Host: Elasticsearch engine host address.
- Port: Elasticsearch engine port.
- Name: Connector name.
- Connector: Elasticsearch driver.
- Log: logging option.
- DefaultSize: Rows to return per page.
- Index: Search engine specific index.
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"}
- First beta version