public ElasticQueryParser(Action <ElasticQueryParserConfiguration> configure = null)
        {
            var config = new ElasticQueryParserConfiguration();

            configure?.Invoke(config);
            _config = config;
        }
        public static ElasticQueryParserConfiguration UseMappings <T>(this ElasticQueryParserConfiguration config, IndexTypeBase <T> indexType) where T : class
        {
            var logger     = indexType.Configuration.LoggerFactory.CreateLogger(typeof(ElasticQueryParserConfiguration));
            var descriptor = indexType.BuildMapping(new TypeMappingDescriptor <T>());

            return(config
                   .UseAliases(indexType.AliasMap)
                   .UseMappings <T>(d => descriptor, () => {
                var response = indexType.Configuration.Client.GetMapping(new GetMappingRequest(indexType.Index.Name, indexType.Name));
                logger.Trace(() => response.GetRequest());
                if (!response.IsValid)
                {
                    logger.Error(response.OriginalException, response.GetErrorMessage());
                }

                return (ITypeMapping)response.Mapping ?? descriptor;
            }));
        }
Пример #3
0
        public static ElasticQueryParserConfiguration UseMappings <T>(this ElasticQueryParserConfiguration config, IndexTypeBase <T> indexType) where T : class
        {
            var logger     = indexType.Configuration.LoggerFactory.CreateLogger(typeof(ElasticQueryParserConfiguration));
            var descriptor = indexType.BuildMapping(new TypeMappingDescriptor <T>());

            return(config
                   .UseAliases(indexType.AliasMap)
                   .UseMappings <T>(d => descriptor, () => {
                var response = indexType.Configuration.Client.GetMapping(new GetMappingRequest(indexType.Index.Name, indexType.Name));
                if (response.IsValid)
                {
                    logger.LogTraceRequest(response);
                }
                else
                {
                    logger.LogErrorRequest(response, "Error getting mapping for index {Name}", indexType.Index.Name);
                }

                return (ITypeMapping)response.Mapping ?? descriptor;
            }));
        }