我将超过 3800 万个文档(文本字符串)加载到本地机器上的 Elasticsearch 索引中。我想计算每个字符串的长度并将该值作为元数据添加到索引中。
在将文档加载到 Elasticsearch 之前,我是否应该将字符串长度计算为元数据?或者,我可以在事后使用计算值更新元数据吗?
我对 Elasticsearch/Kibana 比较陌生,这些问题是由于以下 Python 实验而产生的:
数据作为字符串列表
mylist = ['string_1', 'string_2',..., 'string_N'] L = [len(s) for s in mylist] # this computation takes about 1 minute on my machine
选项 1 的缺点是我没有利用 Elasticsearch,并且“mylist”占用了大量内存。
作为 Elasticsearch 索引的数据,其中“mylist”中的每个字符串都被加载到“text”字段中。
from haystack.document_store.elasticsearch import ElasticsearchDocumentStore document_store = ElasticsearchDocumentStore(host='localhost', username='', password='', index='myindex') docs = document_store.get_all_documents_generator() L = [len(d.text) for d in docs] # this computation takes about 6 minutes on my machine
选项 2 的缺点是计算时间更长。好处是 generator() 释放了内存。较长的计算时间是为什么我认为将字符串长度(和其他分析)作为元数据存储在 Elasticsearch 中是一个很好的解决方案的原因。
我应该考虑其他选择吗?我错过了什么?