Beispiel #1
0
        private string GetPathForTyped <T>(QueryPathDescriptor <T> descriptor) where T : class
        {
            var indices = this.Settings.GetIndexForType <T>();

            if (descriptor._Indices.HasAny())
            {
                indices = string.Join(",", descriptor._Indices);
            }
            else if (descriptor._Indices != null || descriptor._AllIndices)             //if set to empty array asume all
            {
                indices = "_all";
            }

            var types = this.InferTypeName <T>();

            if (descriptor._Types.HasAny())
            {
                types = string.Join(",", descriptor._Types);
            }
            else if (descriptor._Types != null || descriptor._AllTypes)             //if set to empty array assume all
            {
                types = null;
            }

            return(this.PathJoin(indices, types, descriptor._Routing, "_query"));
        }
Beispiel #2
0
        //TODO merge with GetDeleteByQueryPathForDynamic
        public string GetPathForTyped <T>(QueryPathDescriptor <T> descriptor, string suffix) where T : class
        {
            string indices;

            if (descriptor._Indices.HasAny())
            {
                indices = string.Join(",", descriptor._Indices);
            }
            else if (descriptor._Indices != null || descriptor._AllIndices)             //if set to empty array asume all
            {
                indices = "_all";
            }
            else
            {
                indices = this.Infer.IndexName <T>();
            }

            var types = this.Infer.TypeName <T>();

            if (descriptor._Types.HasAny())
            {
                types = string.Join(",", descriptor._Types);
            }
            else if (descriptor._Types != null || descriptor._AllTypes)             //if set to empty array assume all
            {
                types = null;
            }

            return(this.SearchPathJoin(indices, types, descriptor.GetUrlParams(), suffix));
        }
Beispiel #3
0
        public Task <ConnectionStatus> DeleteByQueryAsync(string query, DeleteByQueryParameters parameters = null)
        {
            var descriptor = new QueryPathDescriptor();
            var path       = this.GetPathForDynamic(descriptor);

            if (parameters != null)
            {
                path = this.AppendDeleteByQueryParametersToPath(path, parameters);
            }
            return(this._deleteToPathAsync(path, query));
        }
Beispiel #4
0
        /// <summary>
        /// Deletes all documents that match the query, without specifying T the return documents is an IEnumerable<dynamic>
        /// </summary>
        /// <param name="query">QueryPathDescriptor also allows you to control which indices and types are affected</param>
        /// <param name="parameters">Control routing/consistency and replication</param>
        /// <returns>ConnectionStatus, check .IsValid to validate success</returns>
        public Task <ConnectionStatus> DeleteByQueryAsync(Action <QueryPathDescriptor> query, DeleteByQueryParameters parameters = null)
        {
            var descriptor = new QueryPathDescriptor();

            query(descriptor);
            var stringQuery = ElasticClient.Serialize(descriptor);
            var path        = this.GetPathForDynamic(descriptor);

            if (parameters != null)
            {
                path = this.AppendDeleteByQueryParametersToPath(path, parameters);
            }
            return(this._deleteToPathAsync(path, stringQuery));
        }
Beispiel #5
0
        /// <summary>
        /// Deletes all documents that match the query
        /// </summary>
        /// <param name="query">QueryPathDescriptor also allows you to control which indices and types are affected</param>
        /// <param name="parameters">Control routing/consistency and replication</param>
        /// <returns>ConnectionStatus, check .IsValid to validate success</returns>
        public ConnectionStatus DeleteByQuery <T>(Action <QueryPathDescriptor <T> > query, DeleteByQueryParameters parameters = null) where T : class
        {
            var descriptor = new QueryPathDescriptor <T>();

            query(descriptor);
            var stringQuery = ElasticClient.Serialize(descriptor);
            var path        = this.GetPathForTyped(descriptor);

            if (parameters != null)
            {
                path = this.AppendDeleteByQueryParametersToPath(path, parameters);
            }
            return(this._deleteToPath(path, stringQuery));
        }
Beispiel #6
0
        /// <summary>
        /// Register a percolator
        /// </summary>
        /// <param name="name">Name of the percolator</param>
        /// <param name="querySelector">Path and query descriptor using T to describe the query</param>
        public RegisterPercolateResponse RegisterPercolator <T>(string name, Action <QueryPathDescriptor <T> > querySelector) where T : class
        {
            querySelector.ThrowIfNull("queryDescriptor");
            var descriptor = new QueryPathDescriptor <T>();

            querySelector(descriptor);
            var query = ElasticClient.Serialize(new { query = descriptor });
            var index = this.Settings.GetIndexForType <T>();

            if (descriptor._Indices.HasAny())
            {
                index = descriptor._Indices.First();
            }
            var path = "_percolator/{0}/{1}".F(index, name);

            return(this._RegisterPercolator(path, query));
        }
Beispiel #7
0
        private string GetPathForDynamic(QueryPathDescriptor <dynamic> descriptor)
        {
            var indices = this.Settings.DefaultIndex;

            if (descriptor._Indices.HasAny())
            {
                indices = string.Join(",", descriptor._Indices);
            }
            else if (descriptor._Indices != null || descriptor._AllIndices)             //if set to empty array asume all
            {
                indices = "_all";
            }

            string types = (descriptor._Types.HasAny()) ? string.Join(",", descriptor._Types) : null;

            return(this.PathJoin(indices, types, descriptor._Routing, "_query"));
        }
Beispiel #8
0
        public string GetDeleteByQueryPathForDynamic(QueryPathDescriptor <dynamic> descriptor, string suffix)
        {
            string indices;

            if (descriptor._Indices.HasAny())
            {
                indices = string.Join(",", descriptor._Indices);
            }
            else if (descriptor._Indices != null || descriptor._AllIndices)             //if set to empty array asume all
            {
                indices = "_all";
            }
            else
            {
                indices = this._connectionSettings.DefaultIndex;
            }

            string types = (descriptor._Types.HasAny()) ? string.Join(",", descriptor._Types) : null;

            return(this.SearchPathJoin(indices, types, descriptor.GetUrlParams(), suffix));
        }