Searching for a document immediately after it is saved, i.e. searching for it in its callback/promise will give you no matching results. For example:
client.create({
...
}).then(function (res) {
client.search({ ... }) // no matching results
});
Wildcard query string '*' results in list of matching entries but newly created document missing from that list.
I tried searching after a slight delay (500ms) and the search did come back with the newly saved document.
Elasticsearch by default refreshes each shard every 1s, so the document will be available to search 1s after indexing it.
Search for index.refresh_interval on the indicies settings page. You'll want to set that to either something low or manually call refresh after indexing the document.
Nice; I will try that later this afternoon and update this ticket accordingly.
I see that the JS client has a way to manually refresh indices, but is there a way to pass in the configuration for refresh_interval on client instantiation?
On second thought it seems that it would make better sense to set refresh_interval server-side than client side
So you can set it in the server-side config if this is going to be your use-case, but I'd recommend manually refreshing the index if you're not making a lot of these requests.
Most helpful comment
Elasticsearch by default refreshes each shard every 1s, so the document will be available to search 1s after indexing it.
Search for
index.refresh_intervalon the indicies settings page. You'll want to set that to either something low or manually call refresh after indexing the document.