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 use elasticsearch zone awareness to improve my software development?
- How can I perform a case-insensitive wildcard search using Elasticsearch?
- How can I use Elasticsearch with Zammad?
- How do I check which version of Java is compatible with Elasticsearch?
- How can I use Elasticsearch and ZFS together?
- How can I use Elasticsearch and Zabbix together for software development?
- How can I use Elasticsearch and Zookeeper together to manage distributed applications?
- How can I configure the timeout for an Elasticsearch query?
- How can I use YouTube to learn about Elasticsearch?
- How do I use an Elasticsearch term query?
See more codes...