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 use Elasticsearch and ZFS together?
- How do I set up an Elasticsearch Yum repository?
- How can I use Elasticsearch and Zookeeper together to manage distributed applications?
- How can I use Elasticsearch and Zabbix together for software development?
- How do I use an elasticsearch query builder?
- How can I check the status of a yellow index in Elasticsearch?
- How can I use Elasticsearch with Zammad?
- How can I use Elasticsearch to diagnose "yellow" issues?
- How can I set up and use Elasticsearch on the Yandex Cloud platform?
See more codes...