本文翻译自:Elasticsearch query to return all records
I have a small database in Elasticsearch and for testing purposes would like to pull all records back. 我在Elasticsearch中有一个小型数据库,出于测试目的,我希望将所有记录拉回来。 I am attempting to use a URL of the form... 我试图使用表单的URL ...
http://localhost:9200/foo/_search?pretty=true&q={'matchAll':{''}}
Can someone give me the URL you would use to accomplish this, please? 有人可以给我你用来完成这个的URL吗?
#1楼
参考:https://stackoom.com/question/b2wm/Elasticsearch查询返回所有记录
#2楼
Note: The answer relates to an older version of Elasticsearch
0.90
. 注意:答案与Elasticsearch0.90
的旧版本有关。 Versions released since then have an updated syntax. 从那时起发布的版本具有更新的语法。 Please refer to other answers that may provide a more accurate answer to the latest answer that you are looking for. 请参阅其他答案,以便为您正在寻找的最新答案提供更准确的答案。
The query below would return the NO_OF_RESULTS you would like to be returned.. 下面的查询将返回您想要返回的NO_OF_RESULTS。
curl -XGET 'localhost:9200/foo/_search?size=NO_OF_RESULTS' -d '
{
"query" : {
"match_all" : {}
}
}'
Now, the question here is that you want all the records to be returned. 现在,这里的问题是你想要返回所有记录。 So naturally, before writing a query, you wont know the value of NO_OF_RESULTS . 很自然地,在编写查询之前,您不会知道NO_OF_RESULTS的值。
How do we know how many records exist in your document? 我们如何知道您的文档中存在多少条记录? Simply type the query below 只需在下面输入查询即可
curl -XGET 'localhost:9200/foo/_search' -d '
This would give you a result that looks like the one below 这会给你一个看起来像下面的结果
{
hits" : {
"total" : 2357,
"hits" : [
{
..................
The result total tells you how many records are available in your document. 结果总计告诉您文档中有多少记录可用。 So, that's a nice way to know the value of NO_OF RESULTS 所以,这是了解NO_OF结果值的好方法
curl -XGET 'localhost:9200/_search' -d '
Search all types in all indices 搜索所有索引中的所有类型
curl -XGET 'localhost:9200/foo/_search' -d '
Search all types in the foo index 搜索foo索引中的所有类型
curl -XGET 'localhost:9200/foo1,foo2/_search' -d '
Search all types in the foo1 and foo2 indices 搜索foo1和foo2索引中的所有类型
curl -XGET 'localhost:9200/f*/_search
Search all types in any indices beginning with f 搜索以f开头的任何索引中的所有类型
curl -XGET 'localhost:9200/_all/type1,type2/_search' -d '
Search types user and tweet in all indices 在所有索引中搜索类型用户和推文
#3楼
http://127.0.0.1:9200/foo/_search/?size=1000&pretty=1
^
Note the size param , which increases the hits displayed from the default (10) to 1000 per shard. 请注意大小参数 ,它会将默认值(10)显示的匹配数增加到每个分片1000个。
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-from-size.html http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-from-size.html
#4楼
使用server:9200/_stats
也可以获取有关所有别名的统计信息..如每个别名的大小和元素数量,这非常有用,并提供有用的信息
#5楼
elasticsearch(ES) supports both a GET or a POST request for getting the data from the ES cluster index. elasticsearch(ES)支持从ES集群索引获取数据的GET或POST请求。
When we do a GET: 当我们做GET时:
http://localhost:9200/[your index name]/_search?size=[no of records you want]&q=*:*
When we do a POST: 当我们做POST时:
http://localhost:9200/[your_index_name]/_search
{
"size": [your value] //default 10
"from": [your start index] //default 0
"query":
{
"match_all": {}
}
}
I would suggest to use a UI plugin with elasticsearch http://mobz.github.io/elasticsearch-head/ This will help you get a better feeling of the indices you create and also test your indices. 我建议使用带弹性搜索的UI插件http://mobz.github.io/elasticsearch-head/这将帮助您更好地了解您创建的索引并测试索引。
#6楼
Elasticsearch will get significant slower if you just add some big number as size, one method to use to get all documents is using scan and scroll ids. Elasticsearch将得到显著慢,如果你只需要添加一些大的数量大小,一个方法用来获取所有文档是使用扫描和滚动标识。
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html
In Elasticsearch v7.2, you do it like this: 在Elasticsearch v7.2中,您可以这样做:
POST /foo/_search?scroll=1m
{
"size": 100,
"query": {
"match_all": {}
}
}
The results from this would contain a _scroll_id which you have to query to get the next 100 chunk. 这样的结果将包含一个_scroll_id,你必须查询它以获得下一个100块。
POST /_search/scroll
{
"scroll" : "1m",
"scroll_id" : "<YOUR SCROLL ID>"
}