Elasticsearch bash script not working but if I copy and paste in the terminal it works Elasticsearch bash script not working but if I copy and paste in the terminal it works elasticsearch elasticsearch

Elasticsearch bash script not working but if I copy and paste in the terminal it works


Indexed documents in elasticsearch are not immediately available for searching. They only show up in search after refresh operation takes place. By default this operation occurs automatically every 1sec. So when you paste commands one by one it occurs while you are getting settings and mappings.

When you run bash script there is simply no time for refresh to take place. So, you need to add explicit refresh yourself after the last index command:

curl -XPOST 'http://localhost:9200/products/_refresh?pretty'