ホームページ  >  記事  >  ウェブフロントエンド  >  Elasticsearch の力を解き放つ: リアルタイム検索と分析のトップ ユース ケース

Elasticsearch の力を解き放つ: リアルタイム検索と分析のトップ ユース ケース

WBOY
WBOYオリジナル
2024-08-28 06:02:36362ブラウズ

Unlocking the Power of Elasticsearch: Top Use Cases for Real-Time Search and Analytics

Elasticsearch は、スケーラビリティ、柔軟性、速度に優れた堅牢な分析および検索エンジンです。 Elasticsearch は、大量のデータを処理する必要がある場合でも、非常に短い検索時間が必要な場合でも、信頼性の高いソリューションを提供します。この投稿では、Elasticsearch の最も一般的で重要なユース ケースのいくつかについて説明し、これらのユース ケースの実践に役立つ便利な Node.js の例を提供します。

1️⃣ 全文検索

Elasticsearch の主な使用例の 1 つは全文検索です。これは、ドキュメントを迅速に検索して取得する必要があるアプリケーションにとって非常に重要です。電子商取引サイト、ブログ、ドキュメント管理システムのいずれの検索エンジンを構築する場合でも、Elasticsearch のテキストのインデックス作成と検索を効率的に実行できるため、Elasticsearch は理想的な選択肢となります。

ユースケース: 電子商取引の商品検索

電子商取引プラットフォームでは、ユーザーはさまざまなキーワード、フィルター、カテゴリを使用して商品を検索する必要があります。 Elasticsearch は強力な全文検索機能を可能にし、オートコンプリート、あいまい検索、同義語一致、ファセット検索などの機能を有効にします。

例:

const { Client } = require('@elastic/elasticsearch');
const client = new Client({ node: 'http://localhost:9200' });

async function searchProducts(keyword) {
    const { body } = await client.search({
        index: 'products',
        body: {
            query: {
                match: { product_name: keyword }
            }
        }
    });
    return body.hits.hits;
}

searchProducts('laptop').then(results => console.log(results)).catch(console.error);

2️⃣ リアルタイムログおよびイベントデータ分析

Elasticsearch は、ログやイベント データをリアルタイムで分析するために広く使用されており、監視および可観測性ツールとして人気があります。 Elasticsearch では、ログとイベントにインデックスを付けることで、データをクエリして視覚化し、システムのパフォーマンス、セキュリティ、アプリケーションの動作についての洞察を得ることができます。

ユースケース: ログ管理とモニタリング

最新の DevOps 環境では、サーバー、アプリケーション、ネットワーク デバイスなどのさまざまなソースからのログを管理することが、システムの健全性を維持するために不可欠です。 ELK スタック (Elasticsearch、Logstash、Kibana) は、ログ管理のための強力なソリューションです。

例:

const { Client } = require('@elastic/elasticsearch');
const client = new Client({ node: 'http://localhost:9200' });

async function getRecentLogs() {
    const { body } = await client.search({
        index: 'logs',
        body: {
            query: {
                range: {
                    '@timestamp': {
                        gte: 'now-1h',
                        lte: 'now'
                    }
                }
            }
        }
    });
    return body.hits.hits;
}

getRecentLogs().then(logs => console.log(logs)).catch(console.error);

3️⃣ 地理空間データ検索

Elasticsearch は地理空間データの強力なサポートを提供するため、位置ベースの情報を処理およびクエリする必要があるアプリケーションにとって優れた選択肢となります。 Elasticsearch は、近くの場所の検索から複雑な地理空間分析まで、地理データを操作するための強力なツールを提供します。

ユースケース: 位置情報ベースのサービス

ライドシェアリング、配送サービス、不動産プラットフォームなどのアプリケーションでは、多くの場合、特定の地理的領域内でエンティティを検索したり、地点間の距離を計算したりする必要があります。 Elasticsearch の地理空間機能により、地域フィルタリング、地域集約、ルーティングが可能になります。

例:

const { Client } = require('@elastic/elasticsearch');
const client = new Client({ node: 'http://localhost:9200' });

async function searchNearbyLocations(lat, lon, distance) {
    const { body } = await client.search({
        index: 'places',
        body: {
            query: {
                geo_distance: {
                    distance: distance,
                    location: {
                        lat: lat,
                        lon: lon
                    }
                }
            }
        }
    });
    return body.hits.hits;
}

searchNearbyLocations(40.7128, -74.0060, '5km').then(results => console.log(results)).catch(console.error);

4️⃣ アプリケーション パフォーマンス監視 (APM)

Elasticsearch は、アプリケーション パフォーマンス監視 (APM) にもよく使用され、ソフトウェア アプリケーションのパフォーマンスと可用性の追跡に役立ちます。 Elasticsearch はメトリクス、トレース、ログを収集することでリアルタイムのモニタリングを可能にし、パフォーマンスの問題の診断に役立ちます。

ユースケース: アプリケーションのパフォーマンスの監視

マイクロサービス アーキテクチャでは、個々のサービスのパフォーマンスとその相互作用を監視することが重要です。 Elasticsearch は、リクエストの追跡、レイテンシーの監視、リアルタイムでのエラーの追跡に役立ちます。

例:

const { Client } = require('@elastic/elasticsearch');
const client = new Client({ node: 'http://localhost:9200' });

async function getAverageResponseTime() {
    const { body } = await client.search({
        index: 'apm',
        body: {
            query: {
                match: { status: 'success' }
            },
            aggs: {
                avg_response_time: {
                    avg: { field: 'response_time' }
                }
            }
        }
    });
    return body.aggregations.avg_response_time.value;
}

getAverageResponseTime().then(time => console.log(`Average Response Time: ${time}ms`)).catch(console.error);

5️⃣ セキュリティ情報およびイベント管理 (SIEM)

Elasticsearch は、セキュリティの脅威を検出、分析し、対応するために使用されるセキュリティ情報およびイベント管理 (SIEM) システムにおいて重要な役割を果たします。 Elasticsearch は、セキュリティ関連データを取り込んで分析することで、潜在的なセキュリティ侵害や異常を特定するのに役立ちます。

ユースケース: 脅威の検出と対応

サイバーセキュリティでは、脅威を迅速に検出して対応することが重要です。 Elasticsearch の大量のセキュリティ データを処理および分析する機能は、異常検出、相関分析、コンプライアンス レポートに役立ちます。

例:

const { Client } = require('@elastic/elasticsearch');
const client = new Client({ node: 'http://localhost:9200' });

async function detectSuspiciousLoginAttempts() {
    const { body } = await client.search({
        index: 'security',
        body: {
            query: {
                bool: {
                    must: [
                        { match: { event_type: 'login' }},
                        { range: { login_attempts: { gt: 5 }}}
                    ]
                }
            }
        }
    });
    return body.hits.hits;
}

detectSuspiciousLoginAttempts().then(attempts => console.log(attempts)).catch(console.error);

6️⃣ コンテンツのパーソナライズと推奨事項

Elasticsearch はコンテンツ パーソナライゼーション エンジンの強化にも使用でき、ユーザーの好み、行動、過去のやり取りに基づいてパーソナライズされた推奨事項をユーザーに提供するのに役立ちます。

ユースケース: パーソナライズされたコンテンツの推奨

ストリーミング サービス、ニュース Web サイト、オンライン ストアなどのコンテンツ主導型のプラットフォームでは、パーソナライズされたコンテンツを配信することでユーザー エンゲージメントを大幅に強化できます。 Elasticsearch を使用すると、検索結果をパーソナライズし、関連コンテンツを推奨できます。

例:

const { Client } = require('@elastic/elasticsearch');
const client = new Client({ node: 'http://localhost:9200' });

async function getPersonalizedRecommendations(userId) {
    const { body } = await client.search({
        index: 'user_content',
        body: {
            query: {
                more_like_this: {
                    fields: ['description', 'title'],
                    like: userId,
                    min_term_freq: 1,
                    max_query_terms: 12
                }
            }
        }
    });
    return body.hits.hits;
}

getPersonalizedRecommendations('user123').then(recommendations => console.log(recommendations)).catch(console.error);

7️⃣ Business Intelligence and Data Analytics

Elasticsearch’s ability to handle and analyze large datasets in real time makes it an excellent tool for business intelligence and data analytics. Companies can leverage Elasticsearch to gain insights into their operations, customer behavior, and market trends.

Use Case: Real-Time Business Analytics

Businesses often need to analyze data from multiple sources to make informed decisions. Elasticsearch can be used to analyze sales data, customer behavior, and market trends in real-time.

Example:

const { Client } = require('@elastic/elasticsearch');
const client = new Client({ node: 'http://localhost:9200' });

async function analyzeSalesData() {
    const { body } = await client.search({
        index: 'sales',
        body: {
            query: {
                range: {
                    sale_date: {
                        gte: 'now-1M/M',
                        lte: 'now/M'
                    }
                }
            },
            aggs: {
                sales_by_region: {
                    terms: { field: 'region.keyword' }
                }
            }
        }
    });
    return body.aggregations.sales_by_region.buckets;
}

analyzeSalesData().then(data => console.log(data)).catch(console.error);

Conclusion

Elasticsearch is a flexible tool that may be used for many different purposes, including real-time analytics and full-text search. Elasticsearch is a great option for any application that needs strong search and analytical capabilities because of its speed, scalability, and flexibility. This article's Node.js examples show you how to take advantage of Elasticsearch's robust capabilities to create effective, data-driven solutions for your application.

That's all folks ??

以上がElasticsearch の力を解き放つ: リアルタイム検索と分析のトップ ユース ケースの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。