【问题标题】:No filter_path option on Elasticsearch-python bulk helper APIElasticsearch-python 批量助手 API 上没有 filter_path 选项
【发布时间】:2020-03-19 09:09:57
【问题描述】:

_index_bulk API 的响应包含大量信息。此信息可用于对请求进行故障排除或实现重试逻辑,但可能会占用大量带宽。在这个例子中,索引一个 32 字节的文档会产生一个 339 字节的响应(包括标题):

如果我们像下面这样更新/索引文档,

PUT elasticsearch_domain/more-movies/_doc/1
{"title": "Back to the Future"}

它会返回如下响应,

{
  "_index": "more-movies",
  "_type": "_doc",
  "_id": "1",
  "_version": 4,
  "result": "updated",
  "_shards": {
    "total": 2,
    "successful": 2,
    "failed": 0
  },
  "_seq_no": 3,
  "_primary_term": 1
}

现在,如果我们使用 _bulk API 将 filter_path 与我们现有的索引过程一起使用

PUT elasticsearch_domain/more-movies/_doc/1?filter_path=result,_shards.total
{"title": "Back to the Future"}

然后响应会像,

{
  "result": "updated",
  "_shards": {
    "total": 2
  }
}

所以我的问题是如何使用 filter_path 通过Elasticsearch-python bulk API 或流式批量 API 过滤掉响应?

【问题讨论】:

  • 调用搜索时有没有试过设置?像这样response = es.search(index="index", filter_path=["hits.hits.result","hits.hits._shards.total"], body={"query": {"match_all": {}}})
  • @leandrojmp 感谢您的回复,我不想在 search 文档中过滤它,我希望在使用 bulk 索引时打开它
  • 您可以尝试将 filter_path 以相同的方式应用于批量。试试看
  • 在 kibana 上它可以与 _bulk 一起使用,但对如何使用 elasticsearch-python 方法 elasticsearch.helpers.bulk(client, actions, stats_only=False, *args, **kwargs) 感到困惑

标签: python elasticsearch elasticsearch-bulk-api


【解决方案1】:

与搜索功能相同。试试这样:

elasticsearch.helpers.bulk(client, actions, stats_only=False, filter_path=["hits.hits.result","hits.hits._shards.total"])

【讨论】:

  • 我也在考虑使用 *args 作为 filter_path,我会在第二天尝试并让您知道状态。谢谢,先生。
  • 感谢@val,我们使用此代码filter_path=["items.update.result", "items.update._id", "items.update.status"] 而不是hits.hits.result 过滤掉bulk API 的响应
  • 酷,很高兴它有帮助!
猜你喜欢
  • 2020-01-10
  • 2014-11-27
  • 2020-08-12
  • 2022-01-16
  • 2018-02-20
  • 1970-01-01
  • 2018-09-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多