简体   繁体   English

从索引获取所有文档-elasticsearch

[英]Get all documents from an index - elasticsearch

How can I get all documents from an index in elasticsearch without determining the size in the query like 如何在Elasticsearch中从索引中获取所有文档而不确定查询的大小

GET http://localhost:8090/my_index/_search?size=1000&scroll=1m&pretty=true'-d '{"size": 0,"query":{"query_string":{ "match_all" : {}}}}

Thanks 谢谢

According to the ES scan query documentation , size parameter is not just the number of results: 根据ES 扫描查询文档size参数不仅仅是结果数:

The size parameter allows you to configure the maximum number of hits to be returned with each batch of results. size参数允许您配置每批结果返回的最大匹配数。 Each call to the scroll API returns the next batch of results until there are no more results left to return, ie the hits array is empty. 每次对滚动API的调用都会返回下一批结果,直到没有其他要返回的结果为止,即hits数组为空。

To retrieve all the results you need to do subsequent calls to the API in the manner described in the aforementioned documentation, or to use some ready made implementation, like there is in python . 要检索所有结果,您需要按照上述文档中所述的方式对API进行后续调用,或者使用某些现成的实现(例如python中的实现) Here is an example script to dump resulting jsons on stdout: 这是一个示例脚本,用于在stdout上转储生成的json:

import elasticsearch
from elasticsearch.helpers import scan
import json

es = elasticsearch.Elasticsearch('https://localhost:8090')
es_response = scan(
    es,
    index='my_index',
    doc_type='my_doc_type',
    query={"query": { "match_all" : {}}}
)

for item in es_response:
    print(json.dumps(item))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM