【问题标题】:elasticsearch-py search queries substantially slower than curl equivalentelasticsearch-py 搜索查询比 curl 等效的查询要慢得多
【发布时间】:2018-08-29 23:57:48
【问题描述】:

在 Zeppelin 笔记本中,使用 elasticsearch-py 5x 运行以下查询

es = Elasticsearch(["es-host:9200"])
es.search(index="some_index", 
          doc_type="some_type", 
          body={"query": {"term": {"day": "2018_02_04"}}}
)

返回需要 28 分钟。

从同一个笔记本,使用 curl 运行:

curl -XGET 'http://es-host:9200/some_index/some_type/_search?pretty' -H 'Content-Type: application/json' -d'
{"query": {"term": {"day": "2018_02_04"}}}
'

基本上立即返回。

为什么 python 库的性能这么差,有什么办法可以让它这么快?

【问题讨论】:

    标签: python http elasticsearch apache-zeppelin elasticsearch-py


    【解决方案1】:

    我不明白为什么这行得通,但是如果我在查询中添加filter_path,它会像原始 curl 一样快速返回:

    es = Elasticsearch(["es-host:9200"])
    results = es.search(index="some_index", 
          doc_type="some_type", 
          filter_path=['hits.hits._id'],
          body={"query": {"term": {"day": "2018_02_04"}}}
    )
    

    如果有人对此行为有解释,我将不胜感激。

    【讨论】:

    • 如果添加 filter_path 有帮助,那么它可能是由反序列化成本引起的 - 如果您有大量文档,我们在每次响应解码正文时调用 json.loads 可能会占用大量时间.
    【解决方案2】:

    这不是我见过的任何东西,根据这个问题判断我猜你的环境有问题。

    【讨论】:

    • 其他查询在预期时间内运行,特别是 get() 和 mget()
    • 我已经发布了答案。或许您有更深入的见解?
    猜你喜欢
    • 2023-03-14
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    • 2011-09-20
    • 2015-03-08
    • 1970-01-01
    • 1970-01-01
    • 2019-07-02
    相关资源
    最近更新 更多