private static void WritePathField(JsonWriter jsonWriter, SuggestContextPathFieldInfo pathField) { jsonWriter.WritePropertyName(pathField.ESFieldName); jsonWriter.WriteStartObject(); jsonWriter.WritePropertyName("type"); jsonWriter.WriteValue(ElasticSearchClient.GetElasticSearchTypeFromFieldType(FieldType.text)); /*jsonWriter.WritePropertyName("index"); * jsonWriter.WriteValue(false); * jsonWriter.WritePropertyName("store"); * jsonWriter.WriteValue(false);*/ jsonWriter.WritePropertyName("include_in_all"); jsonWriter.WriteValue(false); jsonWriter.WriteEnd(); }
private static void WriteProperties(JsonWriter jsonWriter, BYteWareTypeInfo bti, PropertyInfo propInfo, IElasticSearchFieldProperties props, string fieldName, string type) { #pragma warning disable CC0021 // Use nameof var fieldProps = props as IElasticProperties; jsonWriter.WritePropertyName("type"); jsonWriter.WriteValue(type); if (!string.IsNullOrEmpty(props.Normalizer)) { jsonWriter.WritePropertyName("normalizer"); jsonWriter.WriteValue(props.Normalizer); } else if (type == ElasticSearchClient.GetElasticSearchTypeFromFieldType(FieldType.keyword)) { jsonWriter.WritePropertyName("normalizer"); jsonWriter.WriteValue("lowercase_normalizer"); } if (!string.IsNullOrEmpty(props.Analyzer)) { jsonWriter.WritePropertyName("analyzer"); jsonWriter.WriteValue(props.Analyzer); } if (props.Boost.HasValue) { jsonWriter.WritePropertyName("boost"); jsonWriter.WriteValue(props.Boost.Value); } if (props.DocValues.HasValue) { jsonWriter.WritePropertyName("doc_values"); jsonWriter.WriteValue(props.DocValues.Value); } if (props.EagerGlobalOrdinals.HasValue) { jsonWriter.WritePropertyName("eager_global_ordinals"); jsonWriter.WriteValue(props.EagerGlobalOrdinals.Value); } if (props.FieldData.HasValue) { jsonWriter.WritePropertyName("fielddata"); jsonWriter.WriteValue(props.FieldData.Value); } if (props.ESIndex.HasValue) { jsonWriter.WritePropertyName("index"); jsonWriter.WriteValue(props.ESIndex.Value); } if (props.IndexOptions.HasValue) { jsonWriter.WritePropertyName("index_options"); jsonWriter.WriteValue(Enum.GetName(typeof(IndexOptions), props.IndexOptions.Value)); } if (props.Norms.HasValue) { jsonWriter.WritePropertyName("norms"); jsonWriter.WriteValue(props.Norms.Value); } if (props.PositionOffsetGap.HasValue) { jsonWriter.WritePropertyName("position_offset_gap"); jsonWriter.WriteValue(props.PositionOffsetGap.Value); } if (props.Store.HasValue) { jsonWriter.WritePropertyName("store"); jsonWriter.WriteValue(props.Store.Value); } if (!string.IsNullOrEmpty(props.SearchAnalyzer)) { jsonWriter.WritePropertyName("search_analyzer"); jsonWriter.WriteValue(props.SearchAnalyzer); } if (!string.IsNullOrEmpty(props.SearchQuoteAnalyzer)) { jsonWriter.WritePropertyName("search_quote_analyzer"); jsonWriter.WriteValue(props.SearchQuoteAnalyzer); } if (!string.IsNullOrEmpty(props.Similarity)) { jsonWriter.WritePropertyName("similarity"); jsonWriter.WriteValue(props.Similarity); } if (props.TermVector.HasValue) { jsonWriter.WritePropertyName("term_vector"); jsonWriter.WriteValue(Enum.GetName(typeof(TermVectorOption), props.TermVector.Value)); } if (props.IgnoreAbove.HasValue) { jsonWriter.WritePropertyName("ignore_above"); jsonWriter.WriteValue(props.IgnoreAbove.Value); } if (!string.IsNullOrEmpty(props.NullValue)) { jsonWriter.WritePropertyName("null_value"); jsonWriter.WriteValue(props.NullValue); } if (props.Coerce.HasValue) { jsonWriter.WritePropertyName("coerce"); jsonWriter.WriteValue(props.Coerce.Value); } if (props.IgnoreMalformed.HasValue) { jsonWriter.WritePropertyName("ignore_malformed"); jsonWriter.WriteValue(props.IgnoreMalformed.Value); } if (props.ScalingFactor.HasValue) { jsonWriter.WritePropertyName("scaling_factor"); jsonWriter.WriteValue(props.ScalingFactor.Value); } if (!string.IsNullOrEmpty(props.DateFormat)) { jsonWriter.WritePropertyName("format"); jsonWriter.WriteValue(props.DateFormat); } if (!string.IsNullOrEmpty(props.Locale)) { jsonWriter.WritePropertyName("locale"); jsonWriter.WriteValue(props.Locale); } if (fieldProps != null && fieldProps.IncludeInAll.HasValue) { jsonWriter.WritePropertyName("include_in_all"); jsonWriter.WriteValue(fieldProps.IncludeInAll.Value); } if (props.PreserveSeparators.HasValue) { jsonWriter.WritePropertyName("preserve_separators"); jsonWriter.WriteValue(props.PreserveSeparators.Value); } if (props.PreservePositionIncrements.HasValue) { jsonWriter.WritePropertyName("preserve_position_increments"); jsonWriter.WriteValue(props.PreservePositionIncrements.Value); } if (props.MaxInputLength.HasValue) { jsonWriter.WritePropertyName("max_input_length"); jsonWriter.WriteValue(props.MaxInputLength.Value); } if (fieldProps != null && !string.IsNullOrEmpty(fieldProps.CopyTo)) { jsonWriter.WritePropertyName("copy_to"); jsonWriter.WriteStartArray(); foreach (var item in fieldProps.CopyTo.Split(";, ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)) { jsonWriter.WriteValue(item); } jsonWriter.WriteEndArray(); } if (type == ElasticSearchClient.GetElasticSearchTypeFromFieldType(FieldType.completion)) { var defType = ElasticSearchClient.GetFieldTypeFromType(propInfo.PropertyType); if (defType != FieldType.text && defType != FieldType.keyword) { throw new ElasticIndexException(CaptionHelper.GetLocalizedText(ElasticSearchClient.IndexExceptionGroup, "SuggestNoString")); } var sf = bti.ESSuggestFields.First(t => t.FieldName == fieldName); if (sf.ContextSettings.Any()) { jsonWriter.WritePropertyName("contexts"); jsonWriter.WriteStartArray(); foreach (var ca in sf.ContextSettings) { jsonWriter.WriteStartObject(); jsonWriter.WritePropertyName("name"); jsonWriter.WriteValue(ca.ContextName); jsonWriter.WritePropertyName("type"); jsonWriter.WriteValue(Enum.GetName(typeof(SuggestContextType), ca.ContextType)); if (ca.ContextPathFieldInfo != null) { jsonWriter.WritePropertyName("path"); jsonWriter.WriteValue(ca.ContextPathFieldInfo.ESFieldName); } if (!string.IsNullOrEmpty(ca.Precision)) { jsonWriter.WritePropertyName("precision"); jsonWriter.WriteValue(ca.Precision); } jsonWriter.WriteEndObject(); } jsonWriter.WriteEndArray(); } } #pragma warning restore CC0021 // Use nameof }