After using ES for over a year, I'm now trying to understand a long standing
problem we experience.
Assume I have no gateway configured and I have started ES 0.15.2 in an
embedded manner using Spring inside of a web application. I am using the
Java API to communicate with ES. There is only one instance of ES on my
system, so no clustering.
I have a single index (ppkc) with multiple types. The type I am interested
in is sysinfo, and I want to use dynamic mappings so I have not created an
explicit mapping file.
Scenario #1
If I attempt to index a document, I can turn on debug log statements and see
the index module attempt to locate mappings in the data config path, and I
assume since none are found the default dynamic mapping kicks in.
Any subsequent queries on the 'sysinfo' type return as expected.
Scenario #2
However, if I attempt to query for a document before indexing, I get a
MissingIndexException.
I don't understand why an index succeeds when I perform a query before
indexing a document. If I do the index first then a query, all is well.
So, thinking that I can catch the exception and handle it by
programmatically forcing an index I wrote this function:
private void checkForIndex(Client client, String esIndex) {
final ClusterAdminClient cluster = client.admin().cluster();
cluster.prepareHealth().setWaitForYellowStatus().execute().actionGet();
ClusterStateResponse response =
cluster.prepareState().execute().actionGet();
boolean hasIndex = response.getState().metaData().hasIndex(esIndex);
if(!hasIndex) {
LOG.info("Index Not Found, creating index: " + esIndex);
client.admin().indices().create(createIndexRequest(esIndex)).actionGet();
}
}
However, this doesn't work either. The index is created without issue, but
my query results in this exception:
Caused by: org.elasticsearch.indices.TypeMissingException: [ppkc]
type[sysinfo] missing
at
org.elasticsearch.action.get.TransportGetAction.shardOperation(TransportGetAction.java:95)
at
org.elasticsearch.action.get.TransportGetAction.shardOperation(TransportGetAction.java:62)
at
org.elasticsearch.action.support.single.shard.TransportShardSingleOperationAction$ShardTransportHandler.messageReceived(TransportShardSingleOperationAction.java:250)
at
org.elasticsearch.action.support.single.shard.TransportShardSingleOperationAction$ShardTransportHandler.messageReceived(TransportShardSingleOperationAction.java:239)
at
org.elasticsearch.transport.netty.MessageChannelHandler$RequestHandler.run(MessageChannelHandler.java:238)
at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:680)
Any thoughts?