我在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参考
其他回答
Size参数将显示的命中数从默认值(10)增加到500。
http://localhost:9200/[indexName]/_search?pretty=true&size=500&q=*:*
将from逐步更改为获取所有数据。
http://localhost:9200/[indexName]/_search?size=500&from=0
如果你想提取成千上万的记录,那么……少数人给出了使用“scroll”的正确答案(注意:一些人还建议使用“search_type=scan”。这已被弃用,并在v5.0中被移除。你不需要它)
从一个“search”查询开始,但指定一个“scroll”参数(这里我使用了1分钟的超时):
curl -XGET 'http://ip1:9200/myindex/_search?scroll=1m' -d '
{
"query": {
"match_all" : {}
}
}
'
这包括你的第一批热门作品。但这还没完。上面curl命令的输出是这样的:
{"_scroll_id":"c2Nhbjs1OzUyNjE6NU4tU3BrWi1UWkNIWVNBZW43bXV3Zzs1Mzc3OkhUQ0g3VGllU2FhemJVNlM5d2t0alE7NTI2Mjo1Ti1TcGtaLVRaQ0hZU0FlbjdtdXdnOzUzNzg6SFRDSDdUaWVTYWF6YlU2Uzl3a3RqUTs1MjYzOjVOLVNwa1otVFpDSFlTQWVuN211d2c7MTt0b3RhbF9oaXRzOjIyNjAxMzU3Ow==","took":109,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":22601357,"max_score":0.0,"hits":[]}}
重要的是要有_scroll_id方便,接下来你应该运行以下命令:
curl -XGET 'localhost:9200/_search/scroll' -d'
{
"scroll" : "1m",
"scroll_id" : "c2Nhbjs2OzM0NDg1ODpzRlBLc0FXNlNyNm5JWUc1"
}
'
然而,传递scroll_id并不是设计为手动完成的。最好的办法是编写代码来实现它。例如,在java中:
private TransportClient client = null;
private Settings settings = ImmutableSettings.settingsBuilder()
.put(CLUSTER_NAME,"cluster-test").build();
private SearchResponse scrollResp = null;
this.client = new TransportClient(settings);
this.client.addTransportAddress(new InetSocketTransportAddress("ip", port));
QueryBuilder queryBuilder = QueryBuilders.matchAllQuery();
scrollResp = client.prepareSearch(index).setSearchType(SearchType.SCAN)
.setScroll(new TimeValue(60000))
.setQuery(queryBuilder)
.setSize(100).execute().actionGet();
scrollResp = client.prepareSearchScroll(scrollResp.getScrollId())
.setScroll(new TimeValue(timeVal))
.execute()
.actionGet();
现在在最后一个命令上使用LOOP来提取数据。
http://localhost:9200/foo/_search/?size=1000&pretty=1
您需要指定大小查询参数,因为默认值是10
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": [
{
elasticsearch(ES)既支持GET请求,也支持POST请求,以便从ES集群索引中获取数据。
当我们执行GET操作时:
http://localhost:9200/[your index name]/_search?size=[no of records you want]&q=*:*
当我们做POST时:
http://localhost:9200/[your_index_name]/_search
{
"size": [your value] //default 10
"from": [your start index] //default 0
"query":
{
"match_all": {}
}
}
我建议使用elasticsearch http://mobz.github.io/elasticsearch-head/的UI插件 这将帮助您更好地了解您创建的索引,并测试您的索引。