public static IElasticClient GetClient()
 {
     var node = new Uri("http://localhost:9200");
     var settings = new ConnectionSettings(node);
     settings.DefaultIndex("stackoverflow");
     return new ElasticClient(settings);
 }
Пример #2
0
        static void Main(string[] args)
        {
            var indexName          = "geodocument";
            var connectionPool     = new Elasticsearch.Net.SniffingConnectionPool(new Uri[] { new Uri("http://localhost:9200") });
            var connectionSettings = new Nest.ConnectionSettings(connectionPool);

            connectionSettings.DefaultIndex(indexName);
            connectionSettings.DisableDirectStreaming();
            var elasticClient = new ElasticClient(connectionSettings);
            Func <TypeMappingDescriptor <GeoDocument>, ITypeMapping> typeMapping = m => m
                                                                                   .Dynamic(false)
                                                                                   .Properties(ps => ps
                                                                                               .Keyword(k => k
                                                                                                        .Name(n => n.DocId))
                                                                                               .GeoShape(g => g
                                                                                                         .PointsOnly(false)
                                                                                                         .Name(o => o.GeoField)));

            elasticClient.CreateIndex(new CreateIndexDescriptor(indexName).Mappings(ms => ms.Map(typeMapping)));
            var polygon  = "{\"type\":\"Polygon\",\"coordinates\":[[[5.856956,51.002753],[5.856928,51.002771],[5.856687,51.002853],[5.856956,51.002753]]]}";
            var document = new GeoDocument()
            {
                DocId    = "1",
                GeoField = JsonConvert.DeserializeObject <object>(polygon),
            };
            var indexResponse = elasticClient.IndexDocument(document);

            Console.WriteLine(indexResponse.DebugInformation);

            elasticClient.DeleteIndex(new DeleteIndexRequest(indexName));
            Console.ReadKey();
        }
 public ElasticSearchDataProvider(string connectionString)
 {
     var settings = new ConnectionSettings(new Uri(connectionString));
     settings.DefaultIndex(DEFAULT_INDEX);
     _client = new ElasticClient(settings);
     Initialize();
 }
Пример #4
0
		private static ConnectionSettings DefaultSettings(ConnectionSettings settings) => settings
			.DefaultIndex("default-index")
			.PrettyJson()
			.InferMappingFor<Project>(map => map
				.IndexName("project")
				.IdProperty(p => p.Name)
			)
			.InferMappingFor<CommitActivity>(map => map
				.IndexName("project")
				.TypeName("commits")
			)
			.InferMappingFor<Developer>(map => map
				.IndexName("devs")
				.Ignore(p => p.PrivateValue)
				.Rename(p => p.OnlineHandle, "nickname")
			)
			.InferMappingFor<PercolatedQuery>(map => map
				.IndexName("queries")
				.TypeName(PercolatorType)
			)
			//.EnableTcpKeepAlive(TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(2))
			//.PrettyJson()
			//TODO make this random
			//.EnableHttpCompression()

			.OnRequestDataCreated(data=> data.Headers.Add("TestMethod", ExpensiveTestNameForIntegrationTests()));
Пример #5
0
        public SalusElasticSearch()
        {
            var node = new Uri("http://localhost:9200");
            var settings = new ConnectionSettings(node);
            settings.DefaultIndex("my-application");

            this.client = new ElasticClient(settings);
        }
Пример #6
0
        public SearchService(IConfiguration configuration)
        {
            var connectionString = new Uri(configuration["Search:Url"]);
            var indexName = configuration["Search:IndexName"];

            var settings = new ConnectionSettings(connectionString);
            settings.DefaultIndex(indexName);

            _client = new ElasticClient(settings);
        }
        public SearchProvider()
        {
            esNode = new Uri("http://localhost:9200");
            esSettings = new ConnectionSettings(esNode);
            esSettings.DefaultIndex(def_index);
            esClient = new ElasticClient(esSettings);

            //Shownig Elastic info in Console
            //Console.WriteLine(esClient.NodesInfo().ToString());
            //Console.ReadKey();
        }
Пример #8
0
        protected static ElasticClient GetESClient(PluginConfig pluginConfig)
        {
            using (ConnectionSettings connection = new Nest.ConnectionSettings(new Uri(pluginConfig.ElasticsearchUrl)))
            {
                if (pluginConfig.SecurityType == "basic" && pluginConfig.Username != null && pluginConfig.Password != null)
                {
                    connection.BasicAuthentication(pluginConfig.Username, pluginConfig.Password);
                }

                connection.DefaultIndex("active-homeseer-index");

                ElasticClient client = new Nest.ElasticClient(connection);
                return(client);
            }
        }
Пример #9
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddMvc();

            services.AddTransient <ISearchIndexBuilder, SearchIndexBuilder>();
            services.AddTransient <IBoardGameCsvRowMapper, BoardGameCsvRowMapper>();
            services.AddTransient <IBoardGameCsvReader, BoardGameCsvReader>();
            services.AddTransient <ISearchResultsMapper, SearchResultsMapper>();
            services.AddTransient <ISearcher, Searcher>();
            services.AddTransient <IElasticClient>(s =>
            {
                var node     = new Uri("http://localhost:9201");
                var settings = new Nest.ConnectionSettings(node);
                settings.DefaultIndex("games");
                return(new ElasticClient(settings));
            });
        }
Пример #10
0
		private static ConnectionSettings DefaultSettings(ConnectionSettings settings) => settings
			.DefaultIndex("default-index")
			.PrettyJson()
			.InferMappingFor<Project>(map => map
				.IndexName("project")
				.IdProperty(p => p.Name)
			)
			.InferMappingFor<CommitActivity>(map => map
				.IndexName("project")
				.TypeName("commits")
			)
			.InferMappingFor<Developer>(map => map
				.IndexName("devs")
				.Ignore(p => p.PrivateValue)
				.Rename(p => p.OnlineHandle, "nickname")
			)
			//We try and fetch the test name during integration tests when running fiddler to send the name 
			//as the TestMethod header, this allows us to quickly identify which test sent which request
			.GlobalHeaders(new NameValueCollection
			{
				{ "TestMethod", ExpensiveTestNameForIntegrationTests() }
			});
Пример #11
0
        // Create index for filling data
        // @indexName : whatever
        public void ElasticSearchSetup(string indexName)
        {
            Uri node = new Uri(ElasticServer);
            ConnectionSettings settings = new ConnectionSettings(node);
            settings.DefaultIndex(indexName);
            client = new ElasticClient(settings);

            // create the index if it doesn't exist
            if (!client.IndexExists(indexName).Exists)
            {
                client.CreateIndex(indexName);
            }
        }