elasticsearchHow do I get all documents using Elasticsearch?
To get all documents using Elasticsearch, you need to use the search
API. The following example code will return all documents in a given index:
GET /my_index/_search
{
"query": {
"match_all": {}
}
}
The output of this query will be a JSON object containing the documents:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 3,
"relation": "eq"
},
"max_score": null,
"hits": [
{
"_index": "my_index",
"_type": "_doc",
"_id": "1",
"_score": null,
"_source": {
"name": "John Doe"
}
},
{
"_index": "my_index",
"_type": "_doc",
"_id": "2",
"_score": null,
"_source": {
"name": "Jane Doe"
}
},
{
"_index": "my_index",
"_type": "_doc",
"_id": "3",
"_score": null,
"_source": {
"name": "Foo Bar"
}
}
]
}
}
The code can be broken down into the following parts:
GET /my_index/_search
- This is the endpoint that is used to search the given index."query": { "match_all": {} }
- This is the query that is used to match all documents in the index.
For more information, please refer to the following links:
More of Elasticsearch
- How can I use YouTube to learn about Elasticsearch?
- How can I use elasticsearch zone awareness to improve my software development?
- How can I use Elasticsearch and ZFS together?
- How can I use Elasticsearch and Zabbix together for software development?
- How do I use Elasticsearch with ZGC?
- How can I use Elasticsearch and Zookeeper together to manage distributed applications?
- How can I use Elasticsearch to diagnose "yellow" issues?
- How do I set up an Elasticsearch Yum repository?
- How can I use the cat indices API in Elasticsearch?
- How can I set up and use Elasticsearch on the Yandex Cloud platform?
See more codes...