if (languageNormalization) {
localSettingsGroupIndex.put("index.analysis.analyzer.default.tokenizer","standard");
localSettingsGroupIndex.putArray("index.analysis.analyzer.default.filter", "icu_normalizer","icu_folding","standard","lowercase","stop");
}//TESTED
ElasticSearchManager docIndex = IndexManager.createIndex(sGroupIndex, DocumentPojoIndexMap.documentType_, false, null, docMapping, localSettingsGroupIndex);
if (null == docIndex) { // index has already been referenced, hence createIndex returns null
docIndex = IndexManager.getIndex(sGroupIndex);
}
if (bClearIndex) {
docIndex.deleteMe();
docIndex = IndexManager.createIndex(sGroupIndex, DocumentPojoIndexMap.documentType_, false, null, docMapping, localSettingsGroupIndex);
}
if (null != docIndex) {
try {
docIndex.pingIndex(); // (wait until it's created itself)
}
catch (Exception e) {} // (just make sure this doesn't die horribly)
}
else {
docIndex = IndexManager.getIndex(sGroupIndex);
}
if (null != docIndex) { // should always be true
docIndex.createAlias(sAliasIndex);
docIndex.closeIndex();
}
}
else if (!bParentsOnly) { // A sub-index of a parent
parentCommunityId = getRootCommunity(parentCommunityId);
if (null != parentCommunityId) {
String parentCommunityIdStr = parentCommunityId.toString();
String sParentGroupIndex = new StringBuffer("doc_").append(new ObjectId(parentCommunityIdStr).toString()).toString();
ElasticSearchManager docIndex = IndexManager.getIndex(sParentGroupIndex);
//DEBUG (alias corruption)
// if (null == _aliasInfo) {
// ClusterStateResponse clusterState = docIndex.getRawClient().admin().cluster().state(new ClusterStateRequest()).actionGet();
// _aliasInfo = CrossVersionImmutableMapOfImmutableMaps.getAliases(clusterState.getState().getMetaData());
// }
// else {
// if (_aliasInfo.containsKey(sGroupIndex)) { // has no aliases, we're not good
// return;
// }
// else {
// //DEBUG
// System.out.println("Alias " + sGroupIndex + " has no aliases (but should)");
// ElasticSearchManager docIndex2 = IndexManager.getIndex(sGroupIndex);
// docIndex2.deleteMe();
// }
// }
docIndex.createAlias(sGroupIndex); // for indexing
// (this is going to be tricky when the functionality is fully implemented
// because it will need to handle the parent index splitting)
docIndex.createAlias(sAliasIndex); // for queries
docIndex.closeIndex();
// (do nothing on delete - that will be handled at the parent index level)
}
}
//TESTED (parents, children, and personal + docs_ aliases)
}
else { // (Personal group)
// Just create the dummy index, no different to getting it in practice
Builder localSettingsGroupIndex = ImmutableSettings.settingsBuilder();
localSettingsGroupIndex.put("number_of_shards", 1).put("number_of_replicas", 0); // (ie guaranteed to be local to each ES node)
ElasticSearchManager dummyGroupIndex = IndexManager.createIndex(DocumentPojoIndexMap.dummyDocumentIndex_, DocumentPojoIndexMap.documentType_, false, null, docMapping, localSettingsGroupIndex);
if (null == dummyGroupIndex) {
dummyGroupIndex = IndexManager.getIndex(DocumentPojoIndexMap.dummyDocumentIndex_);
}
// Just create an alias, so that queries work arbitrarily:
dummyGroupIndex.createAlias(sGroupIndex); // (at some point we should delete the sGroupIndex alias, but leave it in for bw compatibility for now)
dummyGroupIndex.createAlias(sAliasIndex); // (never index dummy indices so only need query index)
// (do nothing on delete since don't have any docs in here anyway)
}
}