vania_elasticsearch 1.0.0 copy "vania_elasticsearch: ^1.0.0" to clipboard
vania_elasticsearch: ^1.0.0 copied to clipboard

Production-ready Elasticsearch client, query builder, bulk indexing, and Vania integration.

example/vania_elasticsearch_example.dart

import 'package:vania/database.dart' show Model;
import 'package:vania_elasticsearch/vania_elasticsearch.dart';

class Post extends Model with Searchable {
  Post({int? id, String? title, String? body}) {
    tableName = 'posts';
    if (id != null) attributes['id'] = id;
    if (title != null) attributes['title'] = title;
    if (body != null) attributes['body'] = body;
  }
}

Future<void> main() async {
  Elasticsearch.configure(
    config: ElasticsearchConfig(
      hosts: [Uri.parse('http://localhost:9200')],
      defaultIndex: 'posts',
    ),
  );

  // Low-level indexing.
  await Elasticsearch.index(
    'posts',
  ).document({'title': 'Vania Elasticsearch', 'status': 'published'}, id: 'p1');

  // Model + Searchable — no per-model repo, no boilerplate.
  await Post(id: 1, title: 'Hello Vania', body: 'first post').searchable();
  await bulkIndex([
    Post(id: 2, title: 'Second', body: 'batched'),
    Post(id: 3, title: 'Third', body: 'batched'),
  ], refresh: 'wait_for');

  final hits = await Post().search('vania', fields: ['title', 'body']);
  print(hits.sources);
}
0
likes
150
points
73
downloads

Documentation

Documentation
API reference

Publisher

verified publishervdart.dev

Weekly Downloads

Production-ready Elasticsearch client, query builder, bulk indexing, and Vania integration.

Homepage
Repository (GitHub)
View/report issues

Topics

#server #backend #elasticsearch #search #vania

License

MIT (license)

Dependencies

vania

More

Packages that depend on vania_elasticsearch