【发布时间】: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