我在Elasticsearch中有一个小数据库,出于测试目的,我想把所有记录拉回来。我正在尝试使用表单的URL…
http://localhost:9200/foo/_search?pretty=true&q={'matchAll':{''}}
有人能给我你要用来完成这个的URL吗?
我在Elasticsearch中有一个小数据库,出于测试目的,我想把所有记录拉回来。我正在尝试使用表单的URL…
http://localhost:9200/foo/_search?pretty=true&q={'matchAll':{''}}
有人能给我你要用来完成这个的URL吗?
当前回答
如果仍然有人像我一样寻找从Elasticsearch中检索的所有数据,下面是我所做的。此外,所有的数据意味着,所有的索引和所有的文档类型。我使用的是Elasticsearch 6.3
curl -X GET "localhost:9200/_search?pretty=true" -H 'Content-Type: application/json' -d'
{
"query": {
"match_all": {}
}
}
'
Elasticsearch参考
其他回答
要从所有索引中返回所有记录,您可以执行:
curl -XGET http://35.195.120.21:9200/_all/_search?size=50&pretty
输出:
"took" : 866,
"timed_out" : false,
"_shards" : {
"total" : 25,
"successful" : 25,
"failed" : 0
},
"hits" : {
"total" : 512034694,
"max_score" : 1.0,
"hits" : [ {
"_index" : "grafana-dash",
"_type" : "dashboard",
"_id" : "test",
"_score" : 1.0,
...
我认为lucene语法是受支持的,所以:
http://localhost: 9200 / foo / _search ?漂亮=真的,q = *: *
size默认为10,因此您可能还需要&size=BIGNUMBER来获取超过10个项目。(其中BIGNUMBER等于一个你认为比你的数据集大的数字)
但是,elasticsearch文档建议对于较大的结果集,使用扫描搜索类型。
EG:
curl -XGET 'localhost:9200/foo/_search?search_type=scan&scroll=10m&size=50' -d '
{
"query" : {
"match_all" : {}
}
}'
然后按照上面建议的文档链接继续请求。
EDIT: scan 2.1.0中已弃用。
与按_doc排序的常规滚动请求相比,Scan并没有提供任何好处。弹性文档链接(由@christophe-roussy提供)
通过提供大小,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" : ""
}'
来自Kibana DevTools的:
GET my_index_name/_search
{
"query": {
"match_all": {}
}
}
Elasticsearch 6.x
请求:GET /foo/_search?漂亮= true
Response:在Hits-> total中,给出文档的计数
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1001,
"max_score": 1,
"hits": [
{