【问题标题】:Elasticsearch queries slow performanceElasticsearch 查询会降低性能
【发布时间】:2014-12-25 01:48:19
【问题描述】:

我们已经设置了具有 7 个节点的 elasticsearch 集群。每个节点的配置类似于16G RAM, 8 Core cpu, centos 6

Elasticsearch 版本:1.3.0
堆内存是 - 9000m

1 Master (Non data)
1 Capable master (Non data)
5 Data node

有 10 个索引,其中一个索引有 5500 万个文档 [254Gi(508Gi 有副本)] 大小其余所有索引都有大约 20k 个文档。

每 1 秒有 5-10 个新文档正在索引。

但问题是搜索有点慢。几乎取2000 ms5000 ms 的平均值。一些查询在 1 秒内完成。

映射:

{
    "my_index": {
        "mappings": {
            "product": {
                "_id": {
                    "path": "product_refer_id"
                },
                "properties": {
                    "product_refer_id": {
                        "type": "string"
                    },
                    "body": {
                        "type": "string"
                    },
                    "cat": {
                        "type": "string"
                    },
                    "cat_score": {
                        "type": "float"
                    },
                    "compliant": {
                        "type": "string"
                    },
                    "created": {
                        "type": "integer"
                    },
                    "facets": {
                        "properties": {
                            "ItemsPerCategoryCount": {
                                "properties": {
                                    "terms": {
                                        "properties": {
                                            "field": {
                                                "type": "string"
                                            },
                                            "size": {
                                                "type": "long"
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "fields": {
                        "type": "string"
                    },
                    "from": {
                        "type": "string"
                    }
                    "id": {
                        "type": "string"
                    },
                    "image": {
                        "type": "string"
                    },
                    "lang": {
                        "type": "string"
                    },
                    "main_cat": {
                        "properties": {
                            "Technology": {
                                "type": "double"
                            }
                        }
                    },
                    "md5_product": {
                        "type": "string"
                    },
                    "post_created": {
                        "type": "long"
                    },
                    "query": {
                        "properties": {
                            "bool": {
                                "properties": {
                                    "must": {
                                        "properties": {
                                            "query_string": {
                                                "properties": {
                                                    "default_field": {
                                                        "type": "string"
                                                    },
                                                    "query": {
                                                        "type": "string"
                                                    }
                                                }
                                            },
                                            "range": {
                                                "properties": {
                                                    "main_cat.Technology": {
                                                        "properties": {
                                                            "gte": {
                                                                "type": "string"
                                                            }
                                                        }
                                                    },
                                                    "sub_cat.Technology.computers": {
                                                        "properties": {
                                                            "gte": {
                                                                "type": "string"
                                                            }
                                                        }
                                                    }
                                                }
                                            },
                                            "term": {
                                                "properties": {
                                                    "product.secondary_cat": {
                                                        "type": "string"
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            },
                            "match_all": {
                                "type": "object"
                            }
                        }
                    },
                    "secondary_cat": {
                        "type": "string"
                    },
                    "secondary_cat_score": {
                        "type": "float"
                    },
                    "size": {
                        "type": "long"
                    },
                    "sort": {
                        "properties": {
                            "_uid": {
                                "type": "string"
                            }
                        }
                    },
                    "sub_cat": {
                        "properties": {
                            "Technology": {
                                "properties": {
                                    "audio": {
                                        "type": "double"
                                    },
                                    "computers": {
                                        "type": "double"
                                    },
                                    "gadgets": {
                                        "type": "double"
                                    },
                                    "geekchic": {
                                        "type": "double"
                                    }
                                }
                            }
                        }
                    },
                    "title": {
                        "type": "string"
                    },
                    "product": {
                        "type": "string"
                    }
                }
            }
        }
    }
}

我们正在使用Default Analyzer
有什么建议吗?这个配置还不够吗?

【问题讨论】:

  • 请提供一些关于您正在索引的内容以及索引方式(分析器等)的详细信息
  • @X.L.Ant :添加了映射。谢谢

标签: elasticsearch


【解决方案1】:

看起来索引无法放入内存,因此会有更多的磁盘 I/O 进行。你用固态硬盘吗?如果没有,你应该得到一些。

除此之外,您的节点需要更多资源(内存、CPU)来处理该索引大小。

我对这里的大小有点惊讶:“仅”5500 万个文档大约 250 GB 是巨大的,我看不到你在那里存储了更大的 blob(我可能弄错了,很难从映射定义)。也许您可以考虑保留一些不分析的数据,以防您不需要查询它,而只需检索它。这将减少索引大小。

除此之外,我没有其他想法,不了解所有相关基础架构的详细信息。

【讨论】:

  • 感谢您的建议。我们没有使用 SSD。我们不会只索引 es 中的大型描述或文本 url 和相应的信息。
  • 如果您有 url 和类似信息,我强烈建议您再次在映射中将这些字段定义为 "index": "not_analyzed"。您仍然可以搜索它们,只是在索引时它们没有被标记/过滤等。这也应该会大大提高索引速度。
【解决方案2】:

为了补充 Torsten Engelbrecht 的答案,默认分析器可能是罪魁祸首。该分析器会将每个单词的每种形式作为单独的标记进行索引,这意味着具有复杂变位的语言中的单个动词可以被索引十几次。此外,这会降低搜索结果的质量。如果您的文档包含格式信息(HTML 标记?),这同样适用。

更多,stop words are disabled by default,这意味着例如英文中的每个“the”、“a”……也会被索引。

您应该考虑使用本地化分析器(可能是雪球分析器?)并为文档中使用的语言使用停用词,以限制倒排索引的大小,从而提高性能。

另外,考虑将not_analyzed 字段设置为 md5、url、id 和其他类型的不可搜索字段。

【讨论】:

  • 感谢您的建议。我会尝试你关于分析仪的建议。而且我们没有在 ES 中索引 HTML 标记。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-02-15
  • 2016-02-25
  • 1970-01-01
  • 1970-01-01
  • 2019-02-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多