This package provides seamless integration between Meteor.js collections and Elasticsearch, enabling automatic indexing and search functionalities.
- Automatic Indexing: Sync your Meteor collections with Elasticsearch.
- Real-time Search: Perform search queries directly on your collections using Elasticsearch's powerful query DSL.
- Configurable: Easy to set up with flexible configuration options.
meteor add receptim:elastic-search
To set up Elasticsearch for a specific collection, use the initElasticSearch
function:
import { MyCollection } from '/imports/api/myCollection'
MyCollection.initElasticSearch({
excludedFields: ['field1', 'field2'], // Fields to index
runObserve: true, // Enable real-time indexing (default: true)
startWorker: true, // Start bullMq worker (default: true)
})
You can search the collection using searchAsync
:
const results = await MyCollection.searchAsync('search term', {
currentPage: 1,
pageItems: 10,
})
Use all the search features of Elasticsearch. For advanced search queries, use searchAdvanceAsync
.:
const results = await MyCollection.searchAdvanceAsync({
query: { match: { field1: 'value' } },
currentPage: 1,
pageItems: 10,
})
To sync all documents in the collection to Elasticsearch:
await MyCollection.allDocumentSync({ ms: 1000, limit: 100 })
To delete all documents from the Elasticsearch index:
await MyCollection.deleteAllSearchIndex()