How it works...
Near real-time (NRT) capabilities are automatically managed by Elasticsearch, which automatically refreshes the indices every second if data is changed in them.
To force a refresh before the internal Elasticsearch interval, you can call the refresh API on one or more indices (more indices are comma-separated), or on all the indices.
Elasticsearch doesn't refresh the state of an index at every inserted document to prevent poor performance due to the excessive I/O required in closing and reopening file descriptors.
Generally, the best time to call the refresh is after indexing a lot of data, to be sure that your records are searchable instantly. It's also possible to force a refresh during a document indexing by adding refresh=true as a query parameter. For example:
POST /myindex/_doc/2qLrAfPVQvCRMe7Ku8r0Tw?refresh=true{
"id": "1234",
"date": "2013-06-07T12:14:54",
"customer_id": "customer1",
"sent": true,
"in_stock_items": 0,
"items": [
{
"name": "item1",
"quantity": 3,
"vat": 20
},
{
"name": "item2",
"quantity": 2,
"vat": 20
},
{
"name": "item3",
"quantity": 1,
"vat": 10
}
]
}