Elasticsearch:大文档(PDF、doc、txt)索引的搜索性能很慢

标签 elasticsearch

我在使用映射器附件的 Elasticsearch 中有 65000 个文档(pdf、docx、txt、..等)索引。现在我想使用以下查询在该存储的文档中搜索内容:

"from" : 0, "size" : 50,
"query": {
    "match": {
        "my_attachment.content": req.params.name
     }
}

但需要 20-30 秒才能出结果。这是非常缓慢的 react 。那么我需要做什么才能快速响应?有什么想法吗?

这里是映射:

"my_attachment": {
                  "type": "attachment",
                  "fields": {
                     "content": {
                        "type": "string",
                        "store": true,
                        "term_vector": "with_positions_offsets"
                     }
                 }
}

最佳答案

由于您的机器有 4 个 CPU 和索引 5 个分片,我建议切换到 4 个主分片,这意味着您需要重建索引。采用这种方法的原因是在任何给定时间执行一次查询都将使用 4 个核心。对于其中一个分片,查询需要等待。要在查询时平均分配负载,请使用 4 个主分片(= CPU 内核数),以便在运行查询时不会在 CPU 级别出现太多争用。

此外,通过提供 curl localhost:9200/your_documents_index/_stats 的输出,我看到“获取”部分(从碎片中检索文档)平均每次操作需要 4.2 秒。这可能是拥有非常大的文档或检索大量文档的结果。 size: 50 不是一个很大的数字,但结合大型文档,它会使查询返回结果的时间更长。

content 字段(其中包含实际文档的那个)有 store: true 并且如果您想要突出显示它,文档说

In order to perform highlighting, the actual content of the field is required. If the field in question is stored (has store set to true in the mapping) it will be used, otherwise, the actual _source will be loaded and the relevant field will be extracted from it.

因此,如果您没有为索引禁用 _source,那么将使用它并且不需要存储内容。此外,获取速度更快也没有什么神奇之处,它与文档的大小以及要检索的文档数量密切相关。不使用 store: true 可能会稍微缩短时间。

从节点统计(curl -XGET "http://localhost:9200/_nodes/stats")没有迹象表明节点有内存或 CPU 问题,所以一切都归结为我的以前的建议。

关于Elasticsearch:大文档(PDF、doc、txt)索引的搜索性能很慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38482136/

相关文章:

ruby-on-rails - Elasticsearch query_string多值字段

curl - 列出 ElasticSearch 服务器上的所有索引?

Elasticsearch - 对没有特定字段的文档给予负面提升

java - spring-data-elasticsearch 使用带有嵌套对象的条件

elasticsearch - 使用Elasticsearch索引7TB数据FScrawler在一段时间后停止

python - Elasticsearch 6.7.0 嵌套 "bool", "should","must"查询

elasticsearch - Elasticsearch范围过滤器在日期直方图中不起作用

elasticsearch - 跨集群的ElasticSearch快照

elasticsearch - kafka avro elasticsearch消费者允许未知键

elasticsearch - 如何读取多面搜索查询的JSON输出?