An Elasticsearch connector for Dart. Includes both a thin wrapper around the REST API for indexing and querying and a Warehouse companion adapter for easily adding search and ranking to repositories.
The REST API wrapper can be used in the browser by importing package:elastic_dart/browser_client.dart
.
A simple usage example:
import 'dart:async';
import 'package:elastic_dart/elastic_dart.dart';
main() async {
var es = new Elasticsearch();
await es.createIndex('my_movies', throwIfExists: false);
await es.bulk([
{"index": {"_index": "my_movies", "_type": "movies", "_id": "1"} },
{"name": "The hunger games", "year": "2012" },
{"index": {"_index": "my_movies", "_type": "movies", "_id": "2"} },
{"name": "Titanic", "year": "1997" },
{"index": {"_index": "my_movies", "_type": "movies", "_id": "3"} },
{"name": "Annabelle", "year": "2014" },
{"index": {"_index": "my_movies", "_type": "movies", "_id": "4"} },
{"name": "Star Wars: Episode I - The Phantom Menace", "year": "1999" }
]);
// Wait for Elasticsearch to index the new documents
await new Future.delayed(new Duration(seconds: 2));
var result = await es.search(index: 'my_movies', query: {
"query": {
"match": {"name": "The hunger games"}
}
});
print(result);
}
For usage on the Warehouse adapter see the example folder.
Please file feature requests and bugs at the issue tracker.