use of io.zulia.message.ZuliaIndex.IndexSettings in project zuliasearch by zuliaio.
the class ZuliaIndex method reloadIndexSettings.
public void reloadIndexSettings() throws Exception {
IndexSettings indexSettings = indexService.getIndex(indexName);
indexConfig.configure(indexSettings);
configureFacets();
zuliaPerFieldAnalyzer.refresh();
for (ZuliaShard s : primaryShardMap.values()) {
try {
s.updateIndexSettings();
} catch (Exception ignored) {
}
}
for (ZuliaShard s : replicaShardMap.values()) {
try {
s.updateIndexSettings();
} catch (Exception ignored) {
}
}
}
use of io.zulia.message.ZuliaIndex.IndexSettings in project zuliasearch by zuliaio.
the class ClientIndexConfig method getIndexSettings.
public IndexSettings getIndexSettings() {
IndexSettings.Builder isb = IndexSettings.newBuilder();
if (numberOfShards != null) {
isb.setNumberOfShards(numberOfShards);
}
if (indexName != null) {
isb.setIndexName(indexName);
}
if (defaultSearchFields != null) {
isb.addAllDefaultSearchField(defaultSearchFields);
}
if (requestFactor != null) {
isb.setRequestFactor(requestFactor);
}
if (minShardRequest != null) {
isb.setMinShardRequest(minShardRequest);
}
if (shardCommitInterval != null) {
isb.setShardCommitInterval(shardCommitInterval);
}
if (idleTimeWithoutCommit != null) {
isb.setIdleTimeWithoutCommit(idleTimeWithoutCommit);
}
if (shardTolerance != null) {
isb.setShardTolerance(shardTolerance);
}
if (indexWeight != null) {
isb.setIndexWeight(indexWeight);
}
if (ramBufferMB != null) {
isb.setRamBufferMB(ramBufferMB);
}
for (String fieldName : fieldMap.keySet()) {
FieldConfig fieldConfig = fieldMap.get(fieldName);
isb.addFieldConfig(fieldConfig);
}
for (String analyzerName : analyzerSettingsMap.keySet()) {
isb.addAnalyzerSettings(analyzerSettingsMap.get(analyzerName));
}
return isb.build();
}
use of io.zulia.message.ZuliaIndex.IndexSettings in project zuliasearch by zuliaio.
the class ZuliaIndexManager method loadIndex.
private void loadIndex(String indexName) throws Exception {
IndexSettings indexSettings = indexService.getIndex(indexName);
loadIndex(indexSettings);
}
use of io.zulia.message.ZuliaIndex.IndexSettings in project zuliasearch by zuliaio.
the class ZuliaIndexManager method createIndex.
public CreateIndexResponse createIndex(CreateIndexRequest request) throws Exception {
// if existing index make sure not to allow changing number of shards
LOG.info(getLogPrefix() + " creating index: " + request);
request = new CreateIndexRequestValidator().validateAndSetDefault(request);
if (!request.hasIndexSettings()) {
throw new IllegalArgumentException("Index settings field is required for create index");
}
NodeWeightComputation nodeWeightComputation = new DefaultNodeWeightComputation(indexService, thisNode, currentOtherNodesActive);
IndexSettings indexSettings = request.getIndexSettings();
if (indexSettings.getNumberOfShards() == 0) {
indexSettings = indexSettings.toBuilder().setNumberOfShards(1).build();
} else if (indexSettings.getNumberOfShards() < 0) {
throw new IllegalArgumentException("Number of shards cannot be negative");
}
String indexName = indexSettings.getIndexName();
IndexSettings existingIndex = indexService.getIndex(indexName);
long currentTimeMillis = System.currentTimeMillis();
if (existingIndex == null) {
indexSettings = indexSettings.toBuilder().setCreateTime(currentTimeMillis).build();
IndexMapping.Builder indexMapping = IndexMapping.newBuilder();
indexMapping.setIndexName(indexName);
indexMapping.setNumberOfShards(indexSettings.getNumberOfShards());
for (int i = 0; i < indexSettings.getNumberOfShards(); i++) {
List<Node> nodes = nodeWeightComputation.getNodesSortedByWeight();
ShardMapping.Builder shardMapping = ShardMapping.newBuilder();
Node primaryNode = nodes.remove(0);
shardMapping.setPrimaryNode(primaryNode);
shardMapping.setShardNumber(i);
nodeWeightComputation.addShard(primaryNode, indexSettings, true);
for (int r = 0; r < nodes.size(); r++) {
if (r < indexSettings.getNumberOfReplicas()) {
Node replicaNode = nodes.get(r);
shardMapping.addReplicaNode(replicaNode);
nodeWeightComputation.addShard(replicaNode, indexSettings, false);
} else {
break;
}
}
indexMapping.addShardMapping(shardMapping);
}
indexService.storeIndexMapping(indexMapping.build());
} else {
if (existingIndex.equals(indexSettings)) {
LOG.info("No changes to existing index <" + indexName + ">");
return CreateIndexResponse.newBuilder().build();
}
if (existingIndex.getNumberOfShards() != indexSettings.getNumberOfShards()) {
throw new IllegalArgumentException("Cannot change shards for existing index");
}
// TODO handle changing of replication factor
if (existingIndex.getNumberOfReplicas() != indexSettings.getNumberOfReplicas()) {
throw new IllegalArgumentException("Cannot change replication factor for existing index yet");
}
}
indexSettings = indexSettings.toBuilder().setUpdateTime(currentTimeMillis).build();
indexService.storeIndex(indexSettings);
CreateIndexRequestFederator createIndexRequestFederator = new CreateIndexRequestFederator(thisNode, currentOtherNodesActive, pool, internalClient, this);
try {
@SuppressWarnings("unused") List<CreateIndexResponse> send = createIndexRequestFederator.send(InternalCreateIndexRequest.newBuilder().setIndexName(indexName).build());
} catch (Exception e) {
if (existingIndex == null) {
LOG.log(Level.SEVERE, "Failed to update index <" + request.getIndexSettings().getIndexName() + ">: ", e);
throw new Exception("Failed to update index <" + request.getIndexSettings().getIndexName() + ">: " + e.getMessage());
} else {
throw new Exception("Failed to create index <" + request.getIndexSettings().getIndexName() + ">: " + e.getMessage());
}
}
return CreateIndexResponse.newBuilder().build();
}
use of io.zulia.message.ZuliaIndex.IndexSettings in project zuliasearch by zuliaio.
the class MongoIndexService method getIndexSettingsFromDoc.
private IndexSettings getIndexSettingsFromDoc(Document doc) throws InvalidProtocolBufferException {
Document indexSettingsDoc = (Document) doc.get(INDEX_SETTINGS);
IndexSettings.Builder builder = IndexSettings.newBuilder();
JsonFormat.parser().merge(indexSettingsDoc.toJson(), builder);
return builder.build();
}
Aggregations