elasticsearchHow do I index a JSON document in Elasticsearch?
In order to index a JSON document in Elasticsearch, you must first create an index, which is a logical namespace that points to one or more primary shards and can have zero or more replica shards. To create an index, you can use the PUT
API. For example, the following command creates an index named "my_index":
PUT my_index
Once the index is created, you can index a JSON document into it by using the POST
API. For example, the following command indexes a document with ID 1 into the index "my_index":
POST my_index/_doc/1
{
"name": "John Doe",
"age": 34
}
The following is the output of the above command:
{
"_index": "my_index",
"_type": "_doc",
"_id": "1",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 0,
"_primary_term": 1
}
The parts of the code are:
PUT my_index
: creates an index named "my_index"POST my_index/_doc/1
: indexes a document with ID 1 into the index "my_index"{ "name": "John Doe", "age": 34 }
: the JSON document to be indexed
Helpful links
More of Elasticsearch
- How can I implement a full text search using Elasticsearch?
- How can I use YouTube to learn about Elasticsearch?
- How can I use Elasticsearch to diagnose "yellow" issues?
- How can I use elasticsearch zone awareness to improve my software development?
- How do I configure Elasticsearch with a YML file?
- How can I integrate Elasticsearch into a Yii2 application?
- How can I use Yandex Mirror to access Elasticsearch data?
- How can I use Elasticsearch and ZFS together?
- How do I set up an Elasticsearch Yum repository?
- How can I use Elasticsearch with Zammad?
See more codes...