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
    }
});
const result = await client.search({
    index: 'users',
    body: {
        query: {
            match: {
                name: 'John'
            }
        }
    }
});

Best Practices

  1. Design mappings carefully
  2. Use appropriate analyzers
  3. Optimize queries
  4. Monitor cluster health
  5. Backup regularly

Conclusion

Master Elasticsearch for powerful search! πŸ”