Retrieving Documents by ID
Published on January 17, 2016 by Bo Andersen
Now that we have added and manipulated documents within our Elasticsearch index, let’s now see how we can retrieve data from it. The easiest way of retrieving data in Elasticsearch, is by retrieving documents by ID. You actually saw this in the previous article if you were paying attention (gotcha!).
Simply specify the ID of a document in the request URI, like below.
GET /ecommerce/product/1002
Here are the results:
{
"_index": "ecommerce",
"_type": "product",
"_id": "1002",
"_version": 3,
"found": true,
"_source": {
"name": "Why Elasticsearch is Awesome",
"price": "50.00",
"description": "This book is all about Elasticsearch!",
"status": "active",
"quantity": 10,
"categories": [
{
"name": "Software"
}
],
"tags": [
"elasticsearch",
"programming"
]
}
}
Could it be any easier? Notice that the meta fields _index, _type, _id and _version are part of the result. The _source property contains the document itself.
Here is what you will learn:
- The architecture of Elasticsearch
- Mappings and analyzers
- Many kinds of search queries (simple and advanced alike)
- Aggregations, stemming, auto-completion, pagination, filters, fuzzy searches, etc.
- ... and much more!