private void overrideShardsOnCreate(ESIndexCmd cmd, JObject req) { if (this.NumShardsOnCreate > 0) { req.WriteToken("settings.number_of_shards", NumShardsOnCreate); } }
public void Flush(ESConnection conn) { if (!IsOpen) { return; } ESIndexCmd cmd = createIndexCmd(conn); cmd.Flush(IndexName); }
public void OptionalOptimize(ESConnection conn) { if (OptimizeToSegments <= 0) { return; } if (!IsOpen) { return; } ESIndexCmd cmd = createIndexCmd(conn); cmd.Optimize(IndexName, OptimizeToSegments, OptimizeWait); }
public void PrepareClose(ESConnection conn) { if (!IsOpen) { return; } ESIndexCmd cmd = createIndexCmd(conn); if (savedRefreshInterval != null) { JObject curSettings = new JObject(); curSettings["refresh_interval"] = savedRefreshInterval; cmd.PutSettings(curSettings); conn.Logger.Log("-- RefreshInterval restored to {0}", savedRefreshInterval); } cmd.Flush(IndexName); }
public void OptionalRename(ESConnection conn) { if (!IsOpen || !Active) { return; } IsOpen = false; if (!RenameNeeded) { return; } Logger logger = conn.Logger.Clone(GetType().Name); logger.Log("Optional rename name={0}, alias={1}, gen={2}", IndexName, AliasName, Generations); ESIndexCmd cmd = createIndexCmd(conn); String existingIndexName; cmd.GetIndexMappingsAndRealName(AliasName, out existingIndexName); logger.Log("Optional rename alias={0}, existing={1}", AliasName, existingIndexName); //Check if the current index was created without a timestamp. If so, we will just remove it //This is more or less a backward compat. issue if (String.Compare(AliasName, existingIndexName, StringComparison.InvariantCultureIgnoreCase) == 0) { logger.Log("Removing index {0}", existingIndexName); cmd.RemoveIndex(existingIndexName); } cmd.MoveAllAliases(AliasName, IndexName, existingIndexName); if (ExtraAlias != null) { cmd.CreateAliases(ExtraAlias.SplitStandard(), IndexName); } //Changing the #replica's if requested. if (this.NumReplicasAfterIndexed > 0) { logger.Log("Setting the #replicas for {0} to {1}", IndexName, NumReplicasAfterIndexed); setNumberOfReplicas(conn, IndexName, NumReplicasAfterIndexed); } if (Generations <= 0) { return; } List <String> indexes = cmd.GetIndexes(AliasName, true); logger.Log("Found {0} indexes starting with {1}:", indexes.Count, AliasName); int existingIdx = -1; int currentIdx = -1; for (int i = 0; i < indexes.Count; i++) { String s = indexes[i]; String what = String.Empty; if (String.Equals(s, existingIndexName, StringComparison.InvariantCultureIgnoreCase)) { existingIdx = i; what = " [existing alias]"; } else if (String.Equals(s, IndexName, StringComparison.InvariantCultureIgnoreCase)) { currentIdx = i; what = " [current index]"; } logger.Log("__ " + s + what); } //Check if the returned list is OK (our index should be in, as well as the current alias) if (currentIdx < 0) { throwNotFound(IndexName); } if (existingIdx < 0 && existingIndexName != null) { String msg = notFoundMsg(existingIndexName); Logs.ErrorLog.Log(msg); logger.Log(_LogType.ltError, msg); } //Remove all indexes between the current one and an existing alias. These are artifacts of temp. or crashed imports logger.Log("Removing indexes between existing ({0}) and current ({1})...", existingIdx, currentIdx); for (int i = existingIdx + 1; i < currentIdx; i++) { logger.Log("Removing index {0}", indexes[i]); cmd.RemoveIndex(indexes[i]); } //Remove all indexes between start-of-time and the existing alias, keeping 'generationsToKeep' generations logger.Log("Removing indexes between epoch and existing ({0}), keeping {1} generations...", existingIdx, Generations); for (int i = 0; i <= existingIdx - Generations + 1; i++) { logger.Log("Removing index {0}", indexes[i]); cmd.RemoveIndex(indexes[i]); } }
public bool Create(ESConnection conn, ESIndexCmd._CheckIndexFlags flags) { if (!Active) { return(false); } if (IsOpen) { return(false); } //Switch off append flags if there's nothing to append if (IndexDateTimeFormat == null || Generations == 0) { flags &= ~ESIndexCmd._CheckIndexFlags.AppendDate; } if (ReadOnly) { flags |= ESIndexCmd._CheckIndexFlags.DontCreate; } DocMappings = null; DateTime configDate; JObject configJson = onLoadConfig(this, ConfigFile, out configDate); patchConfig(conn, configJson); ESIndexCmd cmd = createIndexCmd(conn); cmd.OnCreate = overrideShardsOnCreate; bool isNew; IndexName = cmd.CheckIndexFromFile(AliasName, configJson, configDate, flags, out isNew);//PW naar kijken! IndexExists = IndexName != null; IsNewIndex = isNew; RenameNeeded = (flags & ESIndexCmd._CheckIndexFlags.AppendDate) != 0 && isNew; //Get possible mappings and determine default doctype conn.Logger.Log(""); conn.Logger.Log("get mappings"); DocMappings = new List <String>(); if (IndexName != null) //Might be null if the index was not found (if Readonly==true) { ESGetMappingResponse resp = cmd.GetIndexMappings(IndexName); conn.Logger.Log("Index[0]={0}", resp[0].Name); foreach (var mapping in resp[0]) { conn.Logger.Log("-- Mapping={0}", mapping.Name); DocMappings.Add(mapping.Name); } } if (RefreshIntervalDuringImport != null && !ReadOnly) { JObject curSettings = cmd.GetSettings(); this.savedRefreshInterval = curSettings.ReadStr("refresh_interval", "1s"); curSettings = new JObject(); curSettings["refresh_interval"] = RefreshIntervalDuringImport; cmd.PutSettings(curSettings); conn.Logger.Log("-- RefreshInterval changed from={0} into {1}", savedRefreshInterval, RefreshIntervalDuringImport); } IsOpen = true; return(isNew); }