ElasticsearchStore, a searchNoSqlStore interface. Documents are indexed and queried$ docker run -d --name orm-es \
-e discovery.type=single-node \
-e xpack.security.enabled=false \
-e "ES_JAVA_OPTS=-Xms512m -Xmx512m" \
-p 9200:9200 \
docker.elastic.co/elasticsearch/elasticsearch:8.15.0ES_JAVA_OPTS matters — the default heap is far larger than a laptop or CI$ docker compose up -d --wait # returns once the healthcheck passes
$ docker compose down -v # tear down, volumes included$ until curl -sf "http://127.0.0.1:9200/_cluster/health?wait_for_status=yellow&timeout=1s" >/dev/null; do sleep 1; done$ npm install ts-prorm-orm @elastic/elasticsearchimport { ElasticsearchStore } from 'ts-prorm-orm/nosql/elasticsearch';
const store = new ElasticsearchStore({ node: 'http://127.0.0.1:9200' });
await store.connect();
try {
await store.indexDocument('articles', { title: 'Indexes and constraints' }, { id: '1' });
await store.indexDocument('articles', { title: 'Query optimization' }, { id: '2' });
// Elasticsearch indexes asynchronously; force visibility in a test.
await store.refreshIndex('articles');
const hits = await store.search('articles', {
query: { match: { title: 'query' } },
});
console.log(hits);
} finally {
await store.disconnect();
}@elastic/elasticsearch client's own:import { ElasticsearchStore } from 'ts-prorm-orm/nosql/elasticsearch';
const store = new ElasticsearchStore({
cloud: { id: process.env.ELASTIC_CLOUD_ID! },
auth: { apiKey: process.env.ELASTIC_API_KEY! },
});
await store.connect();refresh call is the single most common source of flaky ElasticsearchindexDocument() resolves. In[!WARNING] Known limitations Documents are searchable only after a refresh (about one second); getDocumentby id is realtime.A field's mapping cannot change once set; create a new index, reindex, and swapAlias.With security disabled (as above) anyone who can reach port 9200 can read and delete everything; keep it on localhost. The container needs vm.max_map_countof at least 262144 on Linux hosts, or it exits at startup.
$ docker rm -f orm-es| Symptom | Cause |
|---|---|
| Container exits immediately, code 137 | OOM-killed. Set ES_JAVA_OPTS as above. |
max virtual memory areas vm.max_map_count [65530] is too low | Linux host needs sysctl -w vm.max_map_count=262144. |
| Health never reaches green | Expected on one node — wait for yellow. |
security_exception | Security is on by default in 8.x; disable it or supply credentials. |
| Document indexed but not found | Needs a refresh — see above. |
elasticsearch — the store's own API notes, in the repository