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 do I set up an Elasticsearch Yum repository?
- How do I configure elasticsearch xpack.security.transport.ssl?
- How can I use Elasticsearch with Zammad?
- How can I use YouTube to learn about Elasticsearch?
- How do I use Yandex with Elasticsearch?
- How do I configure xpack.security.authc.realms in Elasticsearch?
- How can I perform a case-insensitive wildcard search using Elasticsearch?
- How can I use Elasticsearch and Zabbix together for software development?
- How can I use Yandex Mirror to access Elasticsearch data?
- How can I use X-Pack Security with Elasticsearch?
See more codes...