You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

基于Elasticsearch实现多网站搜索的最佳实践咨询

Reusing Existing Elasticsearch Instance vs. Creating a New One for a New Website

Hey there! Great question—this is such a common scenario when expanding Elasticsearch to support multiple applications, so let’s break this down clearly based on Elasticsearch best practices.

Can You Reuse an Existing ES Instance for Different Datasets with Custom Mappings?

Absolutely! This is actually one of Elasticsearch’s core strengths. You can host completely separate datasets (from different databases) on the same ES cluster by using independent indices—each index can have its own custom mappings, settings, and even access controls, keeping your data logically isolated without needing separate clusters.

How to Implement This Properly

If you decide to reuse your existing instance, follow these steps to do it right:

1. Create a Dedicated Index for the New Website

First, define a new index with a clear naming convention (e.g., new-site-products-v1—adding version numbers makes future iterations easier). Specify custom mappings tailored to the new database’s schema, along with cluster-appropriate settings:

PUT /new-site-products-v1
{
  "settings": {
    "number_of_shards": 3, // Adjust based on data size; aim for 10-50GB per shard
    "number_of_replicas": 1 // Critical for high availability
  },
  "mappings": {
    "properties": {
      "product_id": {"type": "keyword"},
      "product_name": {"type": "text", "analyzer": "standard"},
      "price": {"type": "float"},
      "created_at": {"type": "date"}
      // Add other fields matching your new database's structure
    }
  }
}

2. Configure Logstash to Sync New Data to the New Index

Create a separate Logstash configuration file (e.g., new-site-sync.conf) to pull data from your new database and push it to the dedicated index:

input {
  jdbc {
    jdbc_connection_string => "jdbc:mysql://your-new-db-host:3306/new_site_db"
    jdbc_user => "db_user"
    jdbc_password => "db_password"
    jdbc_driver_library => "/path/to/mysql-connector-java.jar"
    jdbc_driver_class => "com.mysql.cj.jdbc.Driver"
    schedule => "* * * * *" // Adjust sync frequency as needed
    statement => "SELECT * FROM products WHERE updated_at > :sql_last_value" // Incremental sync to avoid reprocessing all data
  }
}

output {
  elasticsearch {
    hosts => ["http://your-existing-es-host:9200"]
    index => "new-site-products-v1"
    document_id => "%{product_id}" // Use a unique ID to prevent duplicate entries
  }
}

3. Set Up Role-Based Access Control (RBAC)

If the two websites are managed by different teams or handle sensitive data, use ES’s built-in RBAC to isolate access. For example:

  • Create a new-site-writer role with write permissions only for indices matching new-site-*
  • Create a new-site-reader role with read permissions only for those same indices
  • Assign these roles to the respective service accounts for the new website’s sync and search operations

4. Monitor Resource Usage

Keep an eye on your existing cluster’s CPU, memory, and disk utilization (use Kibana Monitoring or ES’s _cat APIs) to ensure the new index’s workload doesn’t degrade performance for the original website. If you notice resource constraints, consider scaling the cluster (adding nodes) before proceeding.

When to Create a New Elasticsearch Instance Instead?

Reusing isn’t always the best choice. Opt for a new instance if:

  • Critical resource isolation is needed: If your original website’s search is a high-priority core service (e.g., during peak e-commerce traffic), the new workload could cause resource contention. A separate cluster ensures no cross-impact.
  • Version or feature mismatches: If the new website requires newer ES features that your existing cluster can’t support (due to compatibility or upgrade risks), a new instance lets you use the latest version independently.
  • Compliance requirements: If the two datasets fall under different regulatory frameworks (e.g., one handles public data, the other sensitive user information), physical separation simplifies compliance audits.
  • Operational independence: If the two websites are managed by separate teams, a new cluster lets each team own their ES environment without relying on shared resources or permissions.

Final Best Practice Recommendations

  • Prioritize reusing first (with dedicated indices and RBAC) if your cluster has enough resources and no strict isolation requirements—it saves hardware costs and simplifies overall cluster management.
  • Stick to a consistent index naming pattern (like {site}-{data-type}-v{version}) to keep your cluster organized.
  • Enable Index Lifecycle Management (ILM) for both old and new indices to automate hot/cold data tiering, deletion of stale data, and performance optimization.
  • Regularly review cluster health and resource metrics to catch bottlenecks early.

内容的提问来源于stack exchange,提问作者Mamatha Shivanna

火山引擎 最新活动