我在Elasticsearch中有一个小数据库,出于测试目的,我想把所有记录拉回来。我正在尝试使用表单的URL…
http://localhost:9200/foo/_search?pretty=true&q={'matchAll':{''}}
有人能给我你要用来完成这个的URL吗?
我在Elasticsearch中有一个小数据库,出于测试目的,我想把所有记录拉回来。我正在尝试使用表单的URL…
http://localhost:9200/foo/_search?pretty=true&q={'matchAll':{''}}
有人能给我你要用来完成这个的URL吗?
当前回答
您可以使用size=0,这将返回您所有的文档 例子
curl -XGET 'localhost:9200/index/type/_search' -d '
{
size:0,
"query" : {
"match_all" : {}
}
}'
其他回答
http://localhost:9200/foo/_search/?size=1000&pretty=1
您需要指定大小查询参数,因为默认值是10
使用python包elasticsearch-dsl的简单解决方案:
from elasticsearch_dsl import Search
from elasticsearch_dsl import connections
connections.create_connection(hosts=['localhost'])
s = Search(index="foo")
response = s.scan()
count = 0
for hit in response:
# print(hit.to_dict()) # be careful, it will printout every hit in your index
count += 1
print(count)
参见https://elasticsearch-dsl.readthedocs.io/en/latest/api.html#elasticsearch_dsl.Search.scan。
您可以使用size=0,这将返回您所有的文档 例子
curl -XGET 'localhost:9200/index/type/_search' -d '
{
size:0,
"query" : {
"match_all" : {}
}
}'
默认情况下Elasticsearch返回10条记录,因此应该显式提供大小。
添加大小与请求,以获得所需的记录数量。
http://{host}:9200/{index_name}/_search?pretty=true&size=(number的记录)
注意: 最大页面大小不能超过索引。Max_result_window索引设置,默认值为10,000。
通过提供大小,elasticSearch将返回的最大结果是10000
curl -XGET 'localhost:9200/index/type/_search?scroll=1m' -d '
{
"size":10000,
"query" : {
"match_all" : {}
}
}'
在此之后,您必须使用Scroll API来获取结果并获得_scroll_id值,并将此值放入scroll_id中
curl -XGET 'localhost:9200/_search/scroll' -d'
{
"scroll" : "1m",
"scroll_id" : ""
}'