我使用ElasticSearch索引某些数据。但我发现性能不是那么高效。
只有3000个条目数据,每个数据有6列。索引这3000个条目需要5分钟。
因为我是ElasticSearch的新手,所以我的代码和程序流程基本如下:
代码如下:
conn = pyes.ES('server:9200')
搜索:
searchResult = conn.search(searchDict, indexName, TypeName)
索引
conn.index(storeDict, indexName, TypeName, id)
更新索引数据中的Count。
conn.partial_update(indexName, TypeName, id, "ctx._source.Count += counter", params={"counter" : 1})
是否有任何方法可以改善我的代码的性能?
感谢您的帮助。
答案 0 :(得分:1)
更新前无需搜索。 Read the es docs on updating并向下滚动到upsert
部分。 upsert
是一个参数,用于保存要在服务器上不存在文档时使用的文档,否则upsert
将被忽略,它的工作方式与普通update
相同请求(正如您现在所做的那样)。
答案 1 :(得分:1)
您可以使用versioning feature弹性搜索。如果你决定你的文件id很容易。它只是重新索引数据。
您应该使用BULK API进行索引。(1000-5000很好)
效果不佳的另一个原因是config/elasticsearch.yml
上的配置设置,您可以使用此hints来提高索引效果。