Beispiel #1
0
        protected ConnectionSettingsBase(
            IConnectionPool connectionPool,
            IConnection connection,
            ConnectionSettings.SourceSerializerFactory sourceSerializerFactory,
            IPropertyMappingProvider propertyMappingProvider
            )
            : base(connectionPool, connection, null, NestElasticsearchProductRegistration.DefaultForNest)
        {
            var formatterResolver           = new NestFormatterResolver(this);
            var defaultSerializer           = new DefaultHighLevelSerializer(formatterResolver);
            var sourceSerializer            = sourceSerializerFactory?.Invoke(defaultSerializer, this) ?? defaultSerializer;
            var serializerAsMappingProvider = sourceSerializer as IPropertyMappingProvider;

            _propertyMappingProvider = propertyMappingProvider ?? serializerAsMappingProvider ?? new PropertyMappingProvider();

            //We wrap these in an internal proxy to facilitate serialization diagnostics
            _sourceSerializer = new JsonFormatterAwareDiagnosticsSerializerProxy(sourceSerializer, "source");
            UseThisRequestResponseSerializer = new JsonFormatterAwareDiagnosticsSerializerProxy(defaultSerializer);
            _defaultFieldNameInferrer        = p => p.ToCamelCase();
            _defaultIndices       = new FluentDictionary <Type, string>();
            _defaultRelationNames = new FluentDictionary <Type, string>();
            _inferrer             = new Inferrer(this);

            UserAgent(ConnectionSettings.DefaultUserAgent);
        }
Beispiel #2
0
        protected IDictionary <object, object> FieldNameAsKeyFormat(object field, object fieldValue, Action <FluentDictionary <object, object> > moreProperties = null)
        {
            var dict = new FluentDictionary <object, object> {
                { field, fieldValue },
            };

            if (moreProperties != null)
            {
                moreProperties(dict);
            }

            var fb = (IFilter)this;

            if (fb.Cache.HasValue)
            {
                dict.Add("_cache", fb.Cache);
            }
            if (!fb.FilterName.IsNullOrEmpty())
            {
                dict.Add("_name", fb.FilterName);
            }
            if (!fb.CacheKey.IsNullOrEmpty())
            {
                dict.Add("_cache_key", fb.CacheKey);
            }
            return(dict);
        }
        public MultiMatchQueryDescriptor <T> OnFieldsWithBoost(Action <FluentDictionary <Expression <Func <T, object> >, double?> > boostableSelector)
        {
            var d = new FluentDictionary <Expression <Func <T, object> >, double?>();

            boostableSelector(d);
            this._Fields = d.Select(o => PropertyPathMarker.Create(o.Key, o.Value));
            return(this);
        }
        public MultiMatchQueryDescriptor <T> OnFieldsWithBoost(Action <FluentDictionary <string, double?> > boostableSelector)
        {
            var d = new FluentDictionary <string, double?>();

            boostableSelector(d);
            ((IMultiMatchQuery)this).Fields = d.Select(o => PropertyPathMarker.Create(o.Key, o.Value));
            return(this);
        }
Beispiel #5
0
        /// <summary>
        /// Add metadata associated with this percolator query document
        /// </summary>
        public RegisterPercolatorDescriptor <T> AddMetadata(Func <FluentDictionary <string, object>, FluentDictionary <string, object> > selector)
        {
            if (selector == null)
            {
                return(this);
            }

            this._Metadata = selector(new FluentDictionary <string, object>());
            return(this);
        }
Beispiel #6
0
        public ConnectionSettings MapTypeIndices(Action <FluentDictionary <Type, string> > mappingSelector)
        {
            mappingSelector.ThrowIfNull("mappingSelector");

            var dict = new FluentDictionary <Type, string>();

            mappingSelector(dict);
            this._defaultTypeIndices = dict;
            return(this);
        }
Beispiel #7
0
        public SimilarityDescriptor CustomSimilarities(
            Func <FluentDictionary <string, SimilarityBase>, FluentDictionary <string, SimilarityBase> > similaritySelector)
        {
            similaritySelector.ThrowIfNull("similaritySelector");
            var similarities    = new FluentDictionary <string, SimilarityBase>(this._SimilaritySettings.CustomSimilarities);
            var newSimilarities = similaritySelector(similarities);

            this._SimilaritySettings.CustomSimilarities = newSimilarities;
            return(this);
        }
        protected ConnectionSettingsBase(IConnectionPool connectionPool, IConnection connection, Func <TConnectionSettings, IElasticsearchSerializer> serializerFactory)
            : base(connectionPool, connection, serializerFactory)
        {
            this._defaultTypeNameInferrer  = (t => t.Name.ToLowerInvariant());
            this._defaultFieldNameInferrer = (p => p.ToCamelCase());
            this._defaultIndices           = new FluentDictionary <Type, string>();
            this._defaultTypeNames         = new FluentDictionary <Type, string>();

            this._inferrer = new Inferrer(this);
        }
        public QueryStringDescriptor <T> OnFieldsWithBoost(
            Action <FluentDictionary <string, double?> > boostableSelector)
        {
            var d = new FluentDictionary <string, double?>();

            boostableSelector(d);
            var fieldNames = d
                             .Select(o => "{0}^{1}".F(o.Key, o.Value.GetValueOrDefault(1.0).ToString(CultureInfo.InvariantCulture)));

            return(this.OnFields(fieldNames));
        }
Beispiel #10
0
        public AnalysisDescriptor CharFilters(
            Func <FluentDictionary <string, CharFilterBase>, FluentDictionary <string, CharFilterBase> > charFiltersSelecter)
        {
            charFiltersSelecter.ThrowIfNull("charFiltersSelecter");
            var charFilters    = new FluentDictionary <string, CharFilterBase>(this._AnalysisSettings.CharFilters);
            var newCharFilters = charFiltersSelecter(charFilters);

            this._AnalysisSettings.CharFilters = newCharFilters;

            return(this);
        }
Beispiel #11
0
        public AnalysisDescriptor TokenFilters(
            Func <FluentDictionary <string, TokenFilterBase>, FluentDictionary <string, TokenFilterBase> > tokenFiltersSelecter)
        {
            tokenFiltersSelecter.ThrowIfNull("tokenFiltersSelecter");
            var tokenFilters    = new FluentDictionary <string, TokenFilterBase>(this._AnalysisSettings.TokenFilters);
            var newTokenFilters = tokenFiltersSelecter(tokenFilters);

            this._AnalysisSettings.TokenFilters = newTokenFilters;

            return(this);
        }
Beispiel #12
0
        public AnalysisDescriptor Analyzers(
            Func <FluentDictionary <string, AnalyzerBase>, FluentDictionary <string, AnalyzerBase> > analyzerSelector)
        {
            analyzerSelector.ThrowIfNull("analyzerSelector");
            var analyzers    = new FluentDictionary <string, AnalyzerBase>(this._AnalysisSettings.Analyzers);
            var newAnalyzers = analyzerSelector(analyzers);

            this._AnalysisSettings.Analyzers = newAnalyzers;

            return(this);
        }
Beispiel #13
0
        /// <summary>
        /// Instantiate a connectionsettings object to tell the client where and how to connect to elasticsearch
        /// using a proxy
        /// </summary>
        /// <param name="uri">A Uri to describe the elasticsearch endpoint</param>
        /// <param name="timeout">time out in milliseconds</param>
        /// <param name="proxyAddress">proxy address</param>
        /// <param name="username">proxy username</param>
        /// <param name="password">proxy password</param>
        public ConnectionSettings(Uri uri, int timeout, string proxyAddress, string username, string password)
        {
            uri.ThrowIfNull("uri");

            this._uri                    = uri;
            this._password               = password;
            this._username               = username;
            this._timeout                = timeout;
            this._proxyAddress           = proxyAddress;
            this.MaximumAsyncConnections = 20;
            this._defaultTypeIndices     = new FluentDictionary <Type, string>();
        }
Beispiel #14
0
        /// <summary>
        /// Set/Update settings, the index.* prefix is not needed for the keys.
        /// </summary>
        public CreateIndexDescriptor Settings(Action <FluentDictionary <string, object> > settingsSelector)
        {
            settingsSelector.ThrowIfNull("settingsSelector");
            var dict = new FluentDictionary <string, object>();

            settingsSelector(dict);
            foreach (var kv in dict)
            {
                this._indexSettings.Settings.Add(kv.Key, kv.Value);
            }
            return(this);
        }
Beispiel #15
0
        /// <summary>
        /// Instantiate a connectionsettings object to tell the client where and how to connect to elasticsearch
        /// </summary>
        /// <param name="host">host (sans http(s)://), use the Uri constructor overload for more control</param>
        /// <param name="port">port of the host (elasticsearch defaults on 9200)</param>
        /// <param name="timeout">time out in milliseconds</param>
        /// <param name="proxyAddress">proxy address</param>
        /// <param name="username">proxy username</param>
        /// <param name="password">proxy password</param>
        public ConnectionSettings(string host, int port, int timeout, string proxyAddress, string username, string password)
        {
            host.ThrowIfNullOrEmpty("host");
            var uri = new Uri("http://" + host + ":" + port);

            this._host                   = host;
            this._password               = password;
            this._username               = username;
            this._timeout                = timeout;
            this._port                   = port;
            this._proxyAddress           = proxyAddress;
            this.MaximumAsyncConnections = 20;
            this._defaultTypeIndices     = new FluentDictionary <Type, string>();
        }
Beispiel #16
0
        public QueryStringDescriptor <T> OnFieldsWithBoost(
            Action <FluentDictionary <Expression <Func <T, object> >, double?> > boostableSelector)
        {
            var d = new FluentDictionary <Expression <Func <T, object> >, double?>();

            boostableSelector(d);
            var fieldNames = d
                             .Select(o =>
            {
                var field = new PropertyNameResolver().Resolve(o.Key);
                var boost = o.Value.GetValueOrDefault(1.0);
                return("{0}^{1}".F(field, boost.ToString(CultureInfo.InvariantCulture)));
            });

            return(this.OnFields(fieldNames));
        }
Beispiel #17
0
        public ConnectionSettings(Uri uri)
        {
            uri.ThrowIfNull("uri");

            this.Timeout = 60 * 1000;

            this.Uri = uri;
            if (!uri.ToString().EndsWith("/"))
            {
                this.Uri = new Uri(uri.ToString() + "/");
            }
            this.Host = uri.Host;
            this.Port = uri.Port;

            this.MaximumAsyncConnections = 20;
            this.DefaultTypeNameInferrer = this.LowerCaseAndPluralizeTypeNameInferrer;
            this.DefaultIndices          = new FluentDictionary <Type, string>();
            this.DefaultTypeNames        = new FluentDictionary <Type, string>();
        }
        protected ConnectionSettingsBase(
            IConnectionPool connectionPool,
            IConnection connection,
            ConnectionSettings.SourceSerializerFactory sourceSerializerFactory,
            IPropertyMappingProvider propertyMappingProvider
            )
            : base(connectionPool, connection, null)
        {
            var defaultSerializer = new InternalSerializer(this);

            _sourceSerializer = sourceSerializerFactory?.Invoke(defaultSerializer, this) ?? defaultSerializer;
            UseThisRequestResponseSerializer = defaultSerializer;
            _propertyMappingProvider         = propertyMappingProvider ?? new PropertyMappingProvider();

            _defaultTypeNameInferrer  = t => !_defaultTypeName.IsNullOrEmpty() ? _defaultTypeName : t.Name.ToLowerInvariant();
            _defaultFieldNameInferrer = p => p.ToCamelCase();
            _defaultIndices           = new FluentDictionary <Type, string>();
            _defaultTypeNames         = new FluentDictionary <Type, string>();
            _defaultRelationNames     = new FluentDictionary <Type, string>();

            _inferrer = new Inferrer(this);
        }
Beispiel #19
0
        public SearchDescriptor <T> ScriptFields(
            Func <FluentDictionary <string, Func <ScriptFilterDescriptor, ScriptFilterDescriptor> >,
                  FluentDictionary <string, Func <ScriptFilterDescriptor, ScriptFilterDescriptor> > > scriptFields)
        {
            scriptFields.ThrowIfNull("scriptFields");
            var scriptFieldDescriptors = scriptFields(new FluentDictionary <string, Func <ScriptFilterDescriptor, ScriptFilterDescriptor> >());

            if (scriptFieldDescriptors == null || !scriptFieldDescriptors.Any(d => d.Value != null))
            {
                this._ScriptFields = null;
                return(this);
            }
            this._ScriptFields = new FluentDictionary <string, ScriptFilterDescriptor>();
            foreach (var d in scriptFieldDescriptors)
            {
                if (d.Value == null)
                {
                    continue;
                }
                this._ScriptFields.Add(d.Key, d.Value(new ScriptFilterDescriptor()));
            }
            return(this);
        }
        protected ConnectionSettingsBase(
            IConnectionPool connectionPool,
            IConnection connection,
            ConnectionSettings.SourceSerializerFactory sourceSerializerFactory,
            IPropertyMappingProvider propertyMappingProvider
            )
            : base(connectionPool, connection, null)
        {
            var defaultSerializer = new JsonNetSerializer(this);

            this._sourceSerializer = sourceSerializerFactory?.Invoke(defaultSerializer, this) ?? defaultSerializer;
            this.UseThisRequestResponseSerializer = defaultSerializer;
            this._propertyMappingProvider         = propertyMappingProvider ?? new PropertyMappingProvider();

            this._defaultTypeNameInferrer  = (t => t.Name.ToLowerInvariant());
            this._defaultFieldNameInferrer = (p => p.ToCamelCase());
            this._defaultIndices           = new FluentDictionary <Type, string>();
            this._defaultTypeNames         = new FluentDictionary <Type, string>();
            this._defaultRelationNames     = new FluentDictionary <Type, string>();

            this.SerializerFactory = new StatefulSerializerFactory();

            this._inferrer = new Inferrer(this);
        }
        protected ConnectionSettingsBase(
            IConnectionPool connectionPool,
            IConnection connection,
            ConnectionSettings.SourceSerializerFactory sourceSerializerFactory,
            IPropertyMappingProvider propertyMappingProvider
            )
            : base(connectionPool, connection, null)
        {
            var formatterResolver = new NestFormatterResolver(this);
            //Utf8Json.JsonSerializer.SetDefaultResolver(formatterResolver);
            var defaultSerializer = new InternalSerializer(this, formatterResolver);

            _sourceSerializer = sourceSerializerFactory?.Invoke(defaultSerializer, this) ?? defaultSerializer;
            UseThisRequestResponseSerializer = defaultSerializer;
            var serializerAsMappingProvider = _sourceSerializer as IPropertyMappingProvider;

            _propertyMappingProvider = propertyMappingProvider ?? serializerAsMappingProvider ?? new PropertyMappingProvider();

            _defaultFieldNameInferrer = p => p.ToCamelCase();
            _defaultIndices           = new FluentDictionary <Type, string>();
            _defaultTypeNames         = new FluentDictionary <Type, string>();
            _defaultRelationNames     = new FluentDictionary <Type, string>();
            _inferrer = new Inferrer(this);
        }
Beispiel #22
0
 public DateHistogramAggregationDescriptor <T> Params(Func <FluentDictionary <string, object>, FluentDictionary <string, object> > paramSelector)
 {
     this._Params = paramSelector(new FluentDictionary <string, object>());
     return(this);
 }
Beispiel #23
0
 public TMetricAggregation Params(Func <FluentDictionary <string, object>, FluentDictionary <string, object> > paramSelector)
 {
     this._Params = paramSelector(new FluentDictionary <string, object>());
     return((TMetricAggregation)this);
 }