コード例 #1
0
        /// <summary>
        /// Update the index settings for the specified index
        /// </summary>
        public SettingsOperationResponse UpdateSettings(string index, IndexSettings settings)
        {
            string path = this.CreatePath(index) + "_settings";

            settings.Settings = settings.Settings
                                .Where(kv => IndexSettings.UpdateWhiteList.Any(p =>
            {
                return(kv.Key.StartsWith(p));
            }
                                                                               )).ToDictionary(kv => kv.Key, kv => kv.Value);

            var sb = new StringBuilder();
            var sw = new StringWriter(sb);

            using (JsonWriter jsonWriter = new JsonTextWriter(sw))
            {
                jsonWriter.WriteStartObject();
                jsonWriter.WritePropertyName("index");
                jsonWriter.WriteStartObject();
                foreach (var kv in settings.Settings)
                {
                    jsonWriter.WritePropertyName(kv.Key);
                    jsonWriter.WriteValue(kv.Value);
                }

                jsonWriter.WriteEndObject();
            }
            string data = sb.ToString();

            var status = this.Connection.PutSync(path, data);

            var r = new SettingsOperationResponse();

            try
            {
                r = JsonConvert.DeserializeObject <SettingsOperationResponse>(status.Result);
            }
            catch
            {
            }
            r.IsValid          = status.Success;
            r.ConnectionStatus = status;
            return(r);
        }
コード例 #2
0
        /// <summary>
        /// Update the index settings for the specified index
        /// </summary>
        public ISettingsOperationResponse UpdateSettings(string index, IndexSettings settings)
        {
            string path = this.PathResolver.CreateIndexPath(index, "_settings");

            settings.Settings = settings.Settings
                                .Where(kv => IndexSettings.UpdateWhiteList.Any(p => kv.Key.StartsWith(p))).ToDictionary(kv => kv.Key, kv => kv.Value);

            string data   = this.Serializer.Serialize(settings, Formatting.None);
            var    status = this.Connection.PutSync(path, data);

            var r = new SettingsOperationResponse();

            try
            {
                r = this.Deserialize <SettingsOperationResponse>(status.Result);
            }
            catch
            {
            }
            r.IsValid          = status.Success;
            r.ConnectionStatus = status;
            return(r);
        }