我在Elasticsearch中有一个小数据库,出于测试目的,我想把所有记录拉回来。我正在尝试使用表单的URL…

http://localhost:9200/foo/_search?pretty=true&q={'matchAll':{''}}

有人能给我你要用来完成这个的URL吗?


当前回答

http://127.0.0.1:9200/foo/_search/?size=1000&pretty=1
                                   ^

请注意size参数,它将每个分片显示的命中数从默认值(10)增加到1000。

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-from-size.html

其他回答

默认情况下Elasticsearch返回10条记录,因此应该显式提供大小。

添加大小与请求,以获得所需的记录数量。

http://{host}:9200/{index_name}/_search?pretty=true&size=(number的记录)

注意: 最大页面大小不能超过索引。Max_result_window索引设置,默认值为10,000。

http://127.0.0.1:9200/foo/_search/?size=1000&pretty=1
                                   ^

请注意size参数,它将每个分片显示的命中数从默认值(10)增加到1000。

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-from-size.html

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插件 这将帮助您更好地了解您创建的索引,并测试您的索引。

除了@Akira Sendoh,没有人回答如何实际获得所有文档。但是即使是这个解决方案也会使我的ES 6.3服务在没有日志的情况下崩溃。对我来说,使用底层elasticsearch-py库唯一有效的是通过使用scroll() api的扫描助手:

from elasticsearch.helpers import scan

doc_generator = scan(
    es_obj,
    query={"query": {"match_all": {}}},
    index="my-index",
)

# use the generator to iterate, dont try to make a list or you will get out of RAM
for doc in doc_generator:
    # use it somehow

然而,现在更简洁的方法似乎是通过elasticsearch-dsl库,它提供了更抽象、更简洁的调用,例如:http://elasticsearch-dsl.readthedocs.io/en/latest/search_dsl.html#hits

curl -XGET '{{IP/localhost}}:9200/{{Index name}}/{{type}}/_search?scroll=10m&pretty' -d '{
"query": {
"filtered": {
"query": {
"match_all": {}
}}'