Issue is fixed by following, Conversations above were helpful in understanding the problem.
Issue is reproducible with use case where kibana with dashboards and visualisations on start up are required and dashboard, visualisation jsons are posted via elasticsearch.
Explanation:
Before posting the dashboard jsons to elastic search,configure the dashboard field types for hits and version fields,
If it is not done then elasticsearch assumes type for those fields as long. and while switching from dashboard to discover it tries to map the field types of the dashboard mapping, there is a mismatch as kibana expects it to be a integer. Following error is received, and discover tab doesn't load
Error: [illegal_argument_exception] Mapper for [hits] conflicts with existing mapping in other types:
[mapper [hits] cannot be changed from type [long] to [int]]
In order to solve this , delete the .kibana index from elastic search and use following curl commands
curl -XDELETE http://ip:port/.kibana
curl -XPUT http://ip:port/.kibana/_mapping/dashboard -d '{"dashboard":{"properties":{"title":{"type":"string"},"hits":{"type":"integer"},"description":{"type":"string"},
"panelsJSON":{"type":"string","optionsJSON":{"type":"string"},"uiStateJSON":{"type":"string"},"version":{"type":"integer"}
"timeRestore":{"type":"boolean"},"timeTo":{"type":"string"},"timeFrom":{"type":"string"},"kibanaSavedObjectMeta":{"properties":{"searchSourceJSON":{"type":"string"}}}}}
}'
then post the dashboard and visualisations jsons to elasticsearch.
Inorder to avoid this issue just, post the PUT request before posting the dashboard and visualisations jsons to elasticsearch.
This issue will not be seen if dashboards are created directly via kibana UI not through elasticsearch.