public static void SetRouteParameters <TParameters, T>( IIndexTypePath <TParameters> path, IConnectionSettingsValues settings, ElasticsearchPathInfo <TParameters> pathInfo) where TParameters : IRequestParameters, new() where T : class { var inferrer = new ElasticInferrer(settings); if (path.Index == null) { path.Index = inferrer.IndexName <T>(); } if (path.Type == null) { path.Type = inferrer.TypeName <T>(); } var index = inferrer.IndexName(path.Index); var type = inferrer.TypeName(path.Type); pathInfo.Index = index; pathInfo.Type = type; }
internal virtual ElasticsearchPathInfo <K> ToPathInfo <K>(IConnectionSettingsValues settings, K queryString) where K : FluentRequestParameters <K>, new() { var inferrer = new ElasticInferrer(settings); if (this._Index == null) { this._Index = inferrer.IndexName <T>(); } if (this._Type == null) { this._Type = inferrer.TypeName <T>(); } var index = new ElasticInferrer(settings).IndexName(this._Index); var type = new ElasticInferrer(settings).TypeName(this._Type); var pathInfo = new ElasticsearchPathInfo <K>() { Index = index, Type = type }; pathInfo.RequestParameters = queryString ?? new K(); pathInfo.RequestParameters.RequestConfiguration(r => this._RequestConfiguration); return(pathInfo); }
public static void SetRouteParameters <TParameters>( IIndexTypePath <TParameters> path, IConnectionSettingsValues settings, ElasticsearchPathInfo <TParameters> pathInfo) where TParameters : IRequestParameters, new() { var inferrer = new ElasticInferrer(settings); if (path.Index == null) { if (path.Type != null && path.Type.Type != null) { path.Index = path.Type.Type; } else { throw new DslException("Index() not specified"); } } if (path.Type == null) { throw new DslException("Type() not specified"); } var index = inferrer.IndexName(path.Index); var type = inferrer.TypeName(path.Type); pathInfo.Index = index; pathInfo.Type = type; }
internal virtual ElasticsearchPathInfo <TParameters> ToPathInfo(IConnectionSettingsValues settings, TParameters queryString) { var inferrer = new ElasticInferrer(settings); if (this._Type == null) { this._Type = inferrer.TypeName <T>(); } var index = !this._Indices.HasAny() ? inferrer.IndexName <T>() : string.Join(",", this._Indices.Select(inferrer.IndexName)); if (this._AllIndices.GetValueOrDefault(false)) { index = "_all"; } var type = new ElasticInferrer(settings).TypeName(this._Type); var pathInfo = base.ToPathInfo(queryString); pathInfo.Index = index; pathInfo.Type = type; return(pathInfo); }
internal virtual ElasticsearchPathInfo <K> ToPathInfo <K>(IConnectionSettings settings, K queryString) where K : FluentQueryString <K>, new() { var inferrer = new ElasticInferrer(settings); if (this._Type == null) { this._Type = inferrer.TypeName <T>(); } var index = !this._Indices.HasAny() ? inferrer.IndexName <T>() : string.Join(",", this._Indices.Select(inferrer.IndexName)); if (this._AllIndices.GetValueOrDefault(false)) { index = "_all"; } var type = new ElasticInferrer(settings).TypeName(this._Type); var pathInfo = new ElasticsearchPathInfo <K>() { Index = index, Type = type }; pathInfo.QueryString = queryString ?? new K(); return(pathInfo); }
/// <summary> /// _msearch needs a specialized json format in the body /// </summary> public string SerializeMultiSearch(IMultiSearchRequest multiSearchRequest) { var sb = new StringBuilder(); var inferrer = new ElasticInferrer(this._settings); var indexName = inferrer.IndexName(multiSearchRequest.Index); foreach (var operation in multiSearchRequest.Operations.Values) { var path = operation.ToPathInfo(this._settings); if (path.Index == indexName) { path.Index = null; } var op = new { index = path.Index, type = path.Type, search_type = this.GetSearchType(operation, multiSearchRequest), preference = operation.Preference, routing = operation.Routing, ignore_unavailable = operation.IgnoreUnavalable }; var opJson = this.Serialize(op, SerializationFormatting.None).Utf8String(); var action = "{0}\n".F(opJson); sb.Append(action); var searchJson = this.Serialize(operation, SerializationFormatting.None).Utf8String(); sb.Append(searchJson + "\n"); } var json = sb.ToString(); return(json); }
internal virtual ElasticsearchPathInfo <K> ToPathInfo <K>(IConnectionSettings settings, K queryString) where K : FluentQueryString <K>, new() { var inferrer = new ElasticInferrer(settings); if (this._Index == null) { this._Index = inferrer.IndexName <T>(); } if (this._Type == null) { this._Type = inferrer.TypeName <T>(); } var index = new ElasticInferrer(settings).IndexName(this._Index); var type = new ElasticInferrer(settings).TypeName(this._Type); var pathInfo = new ElasticsearchPathInfo <K>() { Index = index, Type = type }; pathInfo.QueryString = queryString ?? new K(); return(pathInfo); }
internal virtual ElasticsearchPathInfo <K> ToPathInfo <K>(IConnectionSettings settings, K queryString) where K : FluentQueryString <K>, new() { var inferrer = new ElasticInferrer(settings); if (!this._AllIndices.HasValue && this._Index == null) { this._Index = inferrer.DefaultIndex; } string index = null; if (!this._AllIndices.GetValueOrDefault(false)) { index = inferrer.IndexName(this._Index); } var pathInfo = new ElasticsearchPathInfo <K>() { Index = index, }; pathInfo.QueryString = queryString ?? new K(); return(pathInfo); }
public static void SetRouteParameters <TParameters, T>( IIndicesTypePath <TParameters> path, IConnectionSettingsValues settings, ElasticsearchPathInfo <TParameters> pathInfo) where TParameters : IRequestParameters, new() where T : class { var inferrer = new ElasticInferrer(settings); if (path.Type == null) { path.Type = inferrer.TypeName <T>(); } var index = !path.Indices.HasAny() ? inferrer.IndexName <T>() : string.Join(",", path.Indices.Select(inferrer.IndexName)); if (path.AllIndices.GetValueOrDefault(false)) { index = "_all"; } var type = inferrer.TypeName(path.Type); pathInfo.Index = index; pathInfo.Type = type; }
internal virtual ElasticsearchPathInfo <TParameters> ToPathInfo(IConnectionSettingsValues settings, TParameters queryString) { var inferrer = new ElasticInferrer(settings); var index = this._Index != null?inferrer.IndexName(this._Index) : inferrer.IndexName <T>(); var type = this._Type != null?inferrer.TypeName(this._Type) : inferrer.TypeName <T>(); var id = this._Id ?? inferrer.Id(this._Object); var pathInfo = base.ToPathInfo(queryString); pathInfo.Index = index; pathInfo.Type = type; pathInfo.Id = id; return(pathInfo); }
public string SerializeBulkDescriptor(IBulkRequest bulkRequest) { bulkRequest.ThrowIfNull("bulkRequest"); bulkRequest.Operations.ThrowIfEmpty("Bulk request does not define any operations"); var sb = new StringBuilder(); var inferrer = new ElasticInferrer(this._settings); foreach (var operation in bulkRequest.Operations) { var command = operation.Operation; var index = operation.Index ?? inferrer.IndexName(bulkRequest.Index) ?? inferrer.IndexName(operation.ClrType); var typeName = operation.Type ?? inferrer.TypeName(bulkRequest.Type) ?? inferrer.TypeName(operation.ClrType); var id = operation.GetIdForOperation(inferrer); if (index.EqualsMarker(bulkRequest.Index)) { operation.Index = null; } else { operation.Index = index; } operation.Type = typeName; operation.Id = id; var opJson = this.Serialize(operation, SerializationFormatting.None).Utf8String(); var action = "{{ \"{0}\" : {1} }}\n".F(command, opJson); sb.Append(action); var body = operation.GetBody(); if (body == null) { continue; } var jsonCommand = this.Serialize(body, SerializationFormatting.None).Utf8String(); sb.Append(jsonCommand + "\n"); } var json = sb.ToString(); return(json); }
public static void SetRouteParameters <TParameters, T>( IIndexNamePath <TParameters> path, IConnectionSettingsValues settings, ElasticsearchPathInfo <TParameters> pathInfo) where TParameters : IRequestParameters, new() where T : class { if (path.Name == null) { throw new DslException("missing name route parameter"); } var inferrer = new ElasticInferrer(settings); var index = inferrer.IndexName(path.Index) ?? inferrer.IndexName(typeof(T)) ?? inferrer.DefaultIndex; pathInfo.Index = index; pathInfo.Name = path.Name; }
internal virtual ElasticsearchPathInfo <K> ToPathInfo <K>(IConnectionSettingsValues settings, K queryString) where K : FluentRequestParameters <K>, new() { //start out with defaults var inferrer = new ElasticInferrer(settings); var index = inferrer.IndexName <T>(); var type = inferrer.TypeName <T>(); var pathInfo = new ElasticsearchPathInfo <K>() { Index = index, Type = type }; if (this._Types.HasAny()) { pathInfo.Type = inferrer.TypeNames(this._Types); } else if (this._AllTypes) { pathInfo.Type = null; } else { pathInfo.Type = inferrer.TypeName <T>(); } if (this._Indices.HasAny()) { pathInfo.Index = inferrer.IndexNames(this._Indices); } else if (this._AllIndices && !pathInfo.Type.IsNullOrEmpty()) { pathInfo.Index = "_all"; } else { pathInfo.Index = this._AllIndices ? null : inferrer.IndexName <T>(); } pathInfo.RequestParameters = queryString ?? new K(); pathInfo.RequestParameters.RequestConfiguration(r => this._RequestConfiguration); return(pathInfo); }
/// <summary> /// _msearch needs a specialized json format in the body /// </summary> public string SerializeMultiSearch(MultiSearchDescriptor multiSearchDescriptor) { var sb = new StringBuilder(); var inferrer = new ElasticInferrer(this._settings); foreach (var operation in multiSearchDescriptor._Operations.Values) { var indices = inferrer.IndexNames(operation._Indices); if (operation._AllIndices.GetValueOrDefault(false)) { indices = "_all"; } var index = indices ?? inferrer.IndexName(multiSearchDescriptor._Index) ?? inferrer.IndexName(operation._ClrType); var types = inferrer.TypeNames(operation._Types); var typeName = types ?? inferrer.TypeName(multiSearchDescriptor._Type) ?? inferrer.TypeName(operation._ClrType); if (operation._AllTypes.GetValueOrDefault(false)) { typeName = null; //force empty typename so we'll query all types. } var op = new { index = index, type = typeName, search_type = this.GetSearchType(operation, multiSearchDescriptor), preference = operation._Preference, routing = operation._Routing }; var opJson = this.Serialize(op, SerializationFormatting.None).Utf8String(); var action = "{0}\n".F(opJson); sb.Append(action); var searchJson = this.Serialize(operation, SerializationFormatting.None).Utf8String(); sb.Append(searchJson + "\n"); } var json = sb.ToString(); return(json); }
public static void SetRouteParameters <TParameters, T>( IQueryPath <TParameters> path, IConnectionSettingsValues settings, ElasticsearchPathInfo <TParameters> pathInfo) where TParameters : IRequestParameters, new() where T : class { //start out with defaults var inferrer = new ElasticInferrer(settings); var index = inferrer.IndexName <T>(); var type = inferrer.TypeName <T>(); pathInfo.Index = index; pathInfo.Type = type; if (path.Types.HasAny()) { pathInfo.Type = inferrer.TypeNames(path.Types); } else if (path.AllTypes.GetValueOrDefault(false)) { pathInfo.Type = null; } else { pathInfo.Type = inferrer.TypeName <T>(); } if (path.Indices.HasAny()) { pathInfo.Index = inferrer.IndexNames(path.Indices); } else if (path.AllIndices.GetValueOrDefault(false) && !pathInfo.Type.IsNullOrEmpty()) { pathInfo.Index = "_all"; } else { pathInfo.Index = path.AllIndices.GetValueOrDefault(false) ? null : inferrer.IndexName <T>(); } }
internal virtual ElasticsearchPathInfo <K> ToPathInfo <K>(IConnectionSettings settings, K queryString) where K : FluentQueryString <K>, new() { var inferrer = new ElasticInferrer(settings); var index = this._Index != null?inferrer.IndexName(this._Index) : inferrer.IndexName <T>(); var type = this._Type != null?inferrer.TypeName(this._Type) : inferrer.TypeName <T>(); var id = this._Id ?? inferrer.Id(this._Object); var pathInfo = new ElasticsearchPathInfo <K>() { Index = index, Type = type, Id = id }; pathInfo.QueryString = queryString ?? new K(); return(pathInfo); }
public string SerializeBulkDescriptor(BulkDescriptor bulkDescriptor) { bulkDescriptor.ThrowIfNull("bulkDescriptor"); bulkDescriptor._Operations.ThrowIfEmpty("Bulk descriptor does not define any operations"); var sb = new StringBuilder(); var inferrer = new ElasticInferrer(this._settings); foreach (var operation in bulkDescriptor._Operations) { var command = operation._Operation; var index = operation._Index ?? inferrer.IndexName(bulkDescriptor._Index) ?? inferrer.IndexName(operation._ClrType); var typeName = operation._Type ?? inferrer.TypeName(bulkDescriptor._Type) ?? inferrer.TypeName(operation._ClrType); var id = operation.GetIdForObject(inferrer); operation._Index = index; operation._Type = typeName; operation._Id = id; var opJson = this.Serialize(operation, SerializationFormatting.None).Utf8String(); var action = "{{ \"{0}\" : {1} }}\n".F(command, opJson); sb.Append(action); if (command == "index" || command == "create") { var jsonCommand = this.Serialize(operation._Object, SerializationFormatting.None).Utf8String(); sb.Append(jsonCommand + "\n"); } else if (command == "update") { var jsonCommand = this.Serialize(operation.GetBody(), SerializationFormatting.None).Utf8String(); sb.Append(jsonCommand + "\n"); } } var json = sb.ToString(); return(json); }
internal virtual ElasticsearchPathInfo <TParameters> ToPathInfo(IConnectionSettingsValues settings, TParameters queryString) { var inferrer = new ElasticInferrer(settings); var index = inferrer.IndexName(this._Index); var type = inferrer.TypeName(this._Type); var pathInfo = base.ToPathInfo(queryString); pathInfo.Index = index; pathInfo.Type = type; return(pathInfo); }
internal virtual ElasticsearchPathInfo <TParameters> ToPathInfo(IConnectionSettingsValues settings, TParameters queryString) { //start out with defaults var inferrer = new ElasticInferrer(settings); var index = inferrer.IndexName <T>(); var type = inferrer.TypeName <T>(); var pathInfo = base.ToPathInfo(queryString); pathInfo.Index = index; pathInfo.Type = type; if (this._Types.HasAny()) { pathInfo.Type = inferrer.TypeNames(this._Types); } else if (this._AllTypes) { pathInfo.Type = null; } else { pathInfo.Type = inferrer.TypeName <T>(); } if (this._Indices.HasAny()) { pathInfo.Index = inferrer.IndexNames(this._Indices); } else if (this._AllIndices && !pathInfo.Type.IsNullOrEmpty()) { pathInfo.Index = "_all"; } else { pathInfo.Index = this._AllIndices ? null : inferrer.IndexName <T>(); } return(pathInfo); }
internal virtual ElasticsearchPathInfo <TParameters> ToPathInfo(IConnectionSettingsValues settings, TParameters queryString) { if (this._Name == null) { throw new DslException("missing Repository()"); } var inferrer = new ElasticInferrer(settings); var index = inferrer.IndexName(this._Index) ?? inferrer.DefaultIndex; var pathInfo = base.ToPathInfo(queryString); pathInfo.Index = index; pathInfo.Name = this._Name; return(pathInfo); }
string IUrlParameter.GetString(IConnectionConfigurationValues settings) { return(this.Match( all => "_all", many => { var nestSettings = settings as IConnectionSettingsValues; if (nestSettings == null) { throw new Exception("Tried to pass field name on querysting but it could not be resolved because no nest settings are available"); } var infer = new ElasticInferrer(nestSettings); var indices = many.Indices.Select(i => infer.IndexName(i)).Distinct(); return string.Join(",", indices); } )); }
ElasticsearchPathInfo <SearchQueryString> IPathInfo <SearchQueryString> .ToPathInfo(IConnectionSettings settings) { var pathInfo = new ElasticsearchPathInfo <SearchQueryString>(); pathInfo.HttpMethod = this._QueryString.ContainsKey("source") ? PathInfoHttpMethod.GET : PathInfoHttpMethod.POST; pathInfo.QueryString = this._QueryString; var inferrer = new ElasticInferrer(settings); string indices; if (this._AllIndices.GetValueOrDefault(false)) { indices = !this._AllTypes.GetValueOrDefault(false) ? "_all" : null; } else if (this._Indices.HasAny()) { indices = inferrer.IndexNames(this._Indices); } else { indices = inferrer.IndexName <T>(); } string types; if (this._AllTypes.GetValueOrDefault(false)) { types = null; } else if (this._Types.HasAny()) { types = inferrer.TypeNames(this._Types); } else { types = inferrer.TypeName <T>(); } pathInfo.Index = indices; pathInfo.Type = types; return(pathInfo); }
internal virtual ElasticsearchPathInfo <K> ToPathInfo <K>(IConnectionSettings settings, K queryString) where K : FluentQueryString <K>, new() { if (this._Name == null) { throw new DslException("missing Name()"); } var inferrer = new ElasticInferrer(settings); var index = inferrer.IndexName(this._Index) ?? inferrer.DefaultIndex; var pathInfo = new ElasticsearchPathInfo <K>() { Index = index, Name = this._Name }; pathInfo.QueryString = queryString ?? new K(); return(pathInfo); }
internal virtual ElasticsearchPathInfo <K> ToPathInfo <K>(IConnectionSettingsValues settings, K queryString) where K : FluentRequestParameters <K>, new() { if (this._Name == null) { throw new DslException("missing Repository()"); } var inferrer = new ElasticInferrer(settings); var index = inferrer.IndexName(this._Index) ?? inferrer.DefaultIndex; var pathInfo = new ElasticsearchPathInfo <K>() { Index = index, Name = this._Name }; pathInfo.RequestParameters = queryString ?? new K(); pathInfo.RequestParameters.RequestConfiguration(r => this._RequestConfiguration); return(pathInfo); }
internal virtual ElasticsearchPathInfo <TParameters> ToPathInfo(IConnectionSettingsValues settings, TParameters queryString) { var inferrer = new ElasticInferrer(settings); if (!this._AllIndices.HasValue && this._Index == null) { this._Index = inferrer.DefaultIndex; } string index = null; if (!this._AllIndices.GetValueOrDefault(false)) { index = inferrer.IndexName(this._Index); } var pathInfo = base.ToPathInfo(queryString); pathInfo.Index = index; return(pathInfo); }
public static void SetRouteParameters <TParameters>( IIndexOptionalPath <TParameters> path, IConnectionSettingsValues settings, ElasticsearchPathInfo <TParameters> pathInfo) where TParameters : IRequestParameters, new() { var inferrer = new ElasticInferrer(settings); if (!path.AllIndices.HasValue && path.Index == null) { path.Index = inferrer.DefaultIndex; } string index = null; if (!path.AllIndices.GetValueOrDefault(false)) { index = inferrer.IndexName(path.Index); } pathInfo.Index = index; }
internal virtual ElasticsearchPathInfo <TParameters> ToPathInfo(IConnectionSettingsValues settings, TParameters queryString) { var inferrer = new ElasticInferrer(settings); if (this._Index == null) { throw new DslException("Index() not specified"); } if (this._Type == null) { throw new DslException("Type() not specified"); } var index = inferrer.IndexName(this._Index); var type = inferrer.TypeName(this._Type); var pathInfo = base.ToPathInfo(queryString); pathInfo.Index = index; pathInfo.Type = type; return(pathInfo); }