Problem:
Need to create an elasticsearch index and add documents to that index through Kibana.
Solution Summary:
We can create an Elasticsearch index and add documents easily after from Kibana Devtools. You may also do the same using any HTTP client.
Prerequisites:
[Recipes] Getting Started with Elastic Cloud
[Recipes] Getting Familiar with Kibana and DevTools (Elastic Cloud)
Login to Kibana and go to Dev Tools.
Solution Steps:
Creating an index using PUT
PUT /employee?pretty
Will get a success response.
Verifying the index with _cat/indices
GET /_cat/indices?v
Creating a Document Specifying ID
PUT /employee/_doc/1?pretty
{
"name": "Heartin",
"salary": 10000000
}
Examine the response. It should be similar to:
{
"_index": "employee",
"_type": "_doc",
"_id": "1",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 2,
"failed": 0
},
"_seq_no": 0,
"_primary_term": 1
}
You may also verify using the id returned:
GET /employee/_doc/1?pretty
Creating a Document Without Specifying ID
You may also create a document without specifying an ID using POST
POST /employee/_doc
{
"name": "Sneha"
}
Error Cases
-
Try using PUT to create doc without specifying id.
-
Request:
PUT /employee/_doc
{
"name": "Deny"
} -
Response:
{
"error": "Incorrect HTTP method for uri [/employee/_doc] and method [PUT], allowed: [POST]",
"status": 405
}
-
-
Try doing POST to /employee/
-
Request:
POST /employee/
{
"name": "Deny"
} -
Response:
{
"error": "Incorrect HTTP method for uri [/employee/] and method [POST], allowed: [PUT, GET, DELETE, HEAD]",
"status": 405
} -
Try to do a POST with a different type field
-
Request:
POST /employee/another
{
"name": "Deny"
} -
Response:
...
"illegal_argument_exception",
"reason": "Rejecting mapping update to [employee] as the final mapping would have more than 1 type: [_doc, another]"
},
"status": 400
-
-
Recent comments