Elasticsearch is powerful for search. Here’s how to get started.
Basic Operations
Create Index
await client.indices.create({
index: 'users',
body: {
mappings: {
properties: {
name: { type: 'text' },
email: { type: 'keyword' },
age: { type: 'integer' }
}
}
}
});
Index Document
await client.index({
index: 'users',
id: '1',
body: {
name: 'John Doe',
email: '[email protected]',
age: 30
}
});
Search
const result = await client.search({
index: 'users',
body: {
query: {
match: {
name: 'John'
}
}
}
});
Best Practices
- Design mappings carefully
- Use appropriate analyzers
- Optimize queries
- Monitor cluster health
- Backup regularly
Conclusion
Master Elasticsearch for powerful search! π