Elasticsearch查询性能缓慢

4
我们已经建立了一个由7个节点组成的elasticsearch集群。每个节点的配置如下:16G内存,8核cpu,centos 6
Elasticsearch版本:1.3.0
堆内存为- 9000m
1 Master (Non data)
1 Capable master (Non data)
5 Data node

有10个索引,其中一个索引拥有5500万个文档[254Gi(带副本为508Gi)]的大小,其余所有索引大约有2万个文档。

每秒钟有5-10个新文档进行索引。

但问题在于搜索有点缓慢。平均需要2000毫秒到5000毫秒左右。一些查询在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"
                    }
                }
            }
        }
    }
}

我们正在使用默认分析器。
有什么建议吗?这个配置不够吗?

请提供一些关于您正在索引的内容以及如何进行索引(分析器等)的详细信息。 - xlecoustillier
@X.L.Ant: 添加了映射。谢谢。 - Roopendra
2个回答

1
看起来索引无法放入内存,因此可能会有更多的磁盘 I/O 操作。您使用 SSD 吗?如果没有,建议您购买一些。
此外,您的节点需要更多资源(内存、CPU)来处理索引大小。
我对这里的大小有点惊讶:仅 5500 万个文档就有约 250 GB 的数据量,我没有看到您在那里存储任何更大的 Blob 数据(我可能错了,仅从映射定义很难看出来)。也许您可以考虑保留一些未经分析的数据,以防您不需要查询它,而只需要检索它。这将减少索引大小。
除此之外,我没有其他想法,因为不了解所有相关基础设施的详细信息。

谢谢您的建议。我们没有使用SSD。我们只在ES中索引URL和相关信息,而不是大型描述或文本。 - Roopendra
如果您有URL和类似的信息,我强烈建议在映射中将这些字段定义为"index": "not_analyzed"。您仍然可以搜索它们,只是在索引时不会进行标记化/过滤等操作。这也应该大大提高索引速度。 - Torsten Engelbrecht

1
为了补充Torsten Engelbrecht的回答,缺省分析器可能是问题的一部分。该分析器将每个单词的每种形式索引为单独的标记,这意味着在具有复杂变位的语言中,单个动词可能被索引十几次。此外,这会降低搜索结果的质量。如果您的文档包含格式信息(HTML标记?),也是如此。
另外,停用词默认禁用,这意味着例如英语中的每个“the”、“a”等都将被索引。
您应该考虑使用针对文档所使用语言的本地化分析器(例如snowball分析器)和停用词来限制倒排索引的大小,并因此提高性能。
此外,请考虑将not_analyzed字段作为md5、网址、ID和其他不可搜索的字段。

谢谢您的建议。我会尝试您关于分析器的建议。同时,我们在ES中不索引HTML标记。 - Roopendra

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接