public bool Delete(string id) { var connectionSettings = new ConnectionSettings(MainVariables.conElasticSearch); connectionSettings.SetDefaultIndex("advertisement"); var elasticClient = new ElasticClient(connectionSettings); return elasticClient.Delete(new Nest.DeleteRequest("advertisement", "advertisement", id)).Found; }
public GameDataManager() { try { var elasticSearchUrl = ConfigurationManager.AppSettings["ElasticStoreConnection"]; var index = ConfigurationManager.AppSettings["EIndex_Game"]; _settings = new ConnectionSettings(new Uri(elasticSearchUrl)).SetDefaultIndex(index).PluralizeTypeNames(); _client = new ElasticClient(_settings); var isIndexExist = _client.IndexExists(i => i.Index(index)); if (!isIndexExist.Exists) { _client.CreateIndex(c => c.Index(index)); _settings.SetDefaultIndex(index); _client = new ElasticClient(_settings); } var response = _client.Map<Game>( h => h.Properties(p => p .String(s => s.Name(i => i.GameId).Index(FieldIndexOption.NotAnalyzed)) .String(s => s.Name(i => i.Status).Index(FieldIndexOption.NotAnalyzed)) .String(s => s.Name(i => i.TurnOfPlayer).Index(FieldIndexOption.NotAnalyzed)) .Object<Winner>(o => o.Name(w => w.Winner).Properties(wp => wp.String(f => f.Name(l => l.FacebookId).Index(FieldIndexOption.NotAnalyzed))) ))); IsServerError(response); } catch (Exception ex) { Logger.LogException(ex, _source, "GameDataManager", Severity.Critical); throw; } }
public BlackListDataManager() { try { var elasticSearchUrl = ConfigurationManager.AppSettings["ElasticStoreConnection"]; var index = ConfigurationManager.AppSettings["EIndex_BlackList"]; _settings = new ConnectionSettings(new Uri(elasticSearchUrl)).SetDefaultIndex(index).PluralizeTypeNames(); _client = new ElasticClient(_settings); var isIndexExist = _client.IndexExists(i => i.Index(index)); if (!isIndexExist.Exists) { _client.CreateIndex(c => c.Index(index)); _settings.SetDefaultIndex(index); _client = new ElasticClient(_settings); } var response = _client.Map<BlockedUser>( h => h.MapFromAttributes(10).Properties(p => p .String(s => s.Name(i => i.ByEmail).Index(FieldIndexOption.NotAnalyzed)) .String(s => s.Name(i => i.ToEmail).Index(FieldIndexOption.NotAnalyzed)) )); IsServerError(response); } catch (Exception ex) { Logger.LogException(ex, _soruce, "BlackListDataManager", Severity.Critical); throw; } }
public IElasticClient GetClient(IElasticConnectionSettings settings) { if (settings == null) throw new ArgumentNullException("settings"); var connectionSettings = new ConnectionSettings(settings.Host, settings.Port); connectionSettings.SetDefaultIndex(settings.IndexName); return new ElasticClient(connectionSettings); }
protected override void ConfigureApplicationContainer(TinyIoCContainer container) { container.Register<IAutocompleteFinder, AutocompleteFinder>(); container.Register<IElasticClient>((ctr, param) => { var connectionSettings = new ConnectionSettings(new Uri("http://172.31.170.182:9200/")); connectionSettings.SetDefaultIndex("autocomplete"); return new ElasticClient(connectionSettings); }); }
protected ElasticClient GetClient() { if (_client == null) { var elasticSettings = new ConnectionSettings("127.0.0.1.", 9200); elasticSettings.SetDefaultIndex(index); _client = new ElasticClient(elasticSettings); } return _client; }
/// Constructor public EsClient() { var node = new Uri(ElasticUri); _settings = new ConnectionSettings(node); _settings.SetDefaultIndex(ConfigurationManager.AppSettings["DefaultIndex"]); _settings.MapDefaultTypeNames(m => m.Add(typeof(HadoopMetaDataModels), ConfigurationManager.AppSettings["DefaultIndexType"])); Current = new ElasticClient(_settings); Current.Map<HadoopMetaDataModels>(m => m .MapFromAttributes()); }
public static IElasticClient CreateClient(IContainer container) { var configuration = ClientConfigurationSection.GetConfiguration(); var connectionSettings = new ConnectionSettings( new Uri(configuration.ElasticSearchUrl) ); ConfigureIdProperty(connectionSettings); connectionSettings.SetJsonSerializerSettingsModifier(x => { x.Converters = ContentIndexer.Instance.IndexingConventions.JsonConverters; x.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; }); connectionSettings.SetDefaultTypeNameInferrer(x => typeof(IContent).IsAssignableFrom(x) ? Constants.EPiServerContentTypeName : null); connectionSettings.SetDefaultIndex(container.GetInstance<IndexResolver>().ResolveIndex()); connectionSettings.ExposeRawResponse(); container.Configure(x => x.For<ConnectionSettings>().Use(connectionSettings)); return new ElasticClient(connectionSettings, null, new PreSerializationProccessor(connectionSettings)); }
public void ConfigureElasticClient() { //var setting = new ConnectionSettings(new Uri("http://localhost:9200/"),Constants.INDEX_PERSON); //setting.EnableTrace(); //setting.ExposeRawResponse(); //client = new ElasticClient(setting); var node = new Uri(Constants.ELASTIC_SEARCH_URI); var settings = new ConnectionSettings(node); settings.SetDefaultIndex(Constants.INDEX_PERSON); settings.MapDefaultTypeNames(m => m.Add(typeof(Person), (Constants.INDEX_PERSON))); client = new ElasticClient(settings); client.CreateIndex(ci => ci .Index(Constants.INDEX_PERSON) .AddMapping<Person>(m => m.MapFromAttributes())); }
public List<ClientInformation> GetClientsBy(string name, bool? onlyPossiblyStolen) { ElasticClient esClient; var settings = new ConnectionSettings(new Uri("http://localhost:9200")); settings.SetDefaultIndex(INDEX); esClient = new ElasticClient(settings); //text is always in lowercase in ES if (!string.IsNullOrEmpty(name)) name = name.ToLowerInvariant(); var result = esClient.Search<ClientInformation>( sd => sd.Query( q=> q.Strict(false).Wildcard(t => t.Name,name)) .Filter(f => f.Strict(false).Term(t => t.PossiblyStolen, onlyPossiblyStolen)) ); return result.Documents.ToList(); }
static void Main(string[] args) { var reader = new StreamReader("C:/data/logs/FritzLog.csv"); var csv = new CsvReader(reader); csv.Parser.Configuration.Delimiter = ";"; csv.Configuration.HasHeaderRecord = true; csv.Configuration.IgnoreHeaderWhiteSpace = true; var records = csv.GetRecords<LogEntry>(); var node = new Uri("http://localhost:9200"); var settings = new ConnectionSettings(node); settings.SetDefaultIndex("phonelog"); var client = new ElasticClient(settings); client.DeleteIndex("phonelog"); client.CreateIndex(ci => ci.Index("phonelog").AddMapping<LogEntry>(m => m.MapFromAttributes())); foreach (var record in records) { var result = client.Index(record); Console.WriteLine(record + ", Result: " + result); } }
private static void Index(DocumentModel document, String operation) { var uriString = ConfigurationManager.AppSettings["SEARCHBOX_URL"]; var searchBoxUri = new Uri(uriString); var settings = new ConnectionSettings(searchBoxUri); settings.SetDefaultIndex(indexName); var client = new ElasticClient(settings); if (!client.IndexExists(indexName).Exists) { // Create a new "sample" index with default settings ICreateIndexRequest iCreateIndexReq = new CreateIndexRequest(indexName); iCreateIndexReq.IndexSettings = new IndexSettings(); iCreateIndexReq.IndexSettings.NumberOfReplicas = 10; //iCreateIndexReq.IndexSettings.Mappings = new List<RootObjectMapping>(); //RootObjectMapping rootObjectMapping = new RootObjectMapping(); //rootObjectMapping.AllFieldMapping() //iCreateIndexReq.IndexSettings.Mappings. //client.CreateIndex(iCreateIndexReq); //client.CreateIndex(indexName,s=>s.) var resCreate = client.CreateIndex(indexName, s => s.AddMapping<DocumentModel>(f => f.MapFromAttributes()).NumberOfReplicas(1).NumberOfShards(10)); //client.CreateIndex(indexName, new IndexSettings()); //client.create } if (operation.Equals("delete")) { //client.DeleteById(indexName, "documents", document.DocumentId); IDeleteByQueryRequest iDeleteByQueryRequest = new DeleteByQueryRequest(); //IDeleteIndexRequest delReq = new DeleteIndexRequest(indexName); //client.DeleteIndex() //client.DeleteByQuery(new DeleteByQueryRequest()) client.Delete<DocumentModel>(f => f.Id(document.DocumentId).Index(indexName).Refresh()); //var response = this.Client.Delete<ElasticsearchProject>(f=>f.Id(newDocument.Id).Index(newIndex).Refresh()); } else { //IIndexRequest<DocumentModel> indexRequest = IndexRequest<DocumentModel>(); //client.Index(i) //client.Index(document, indexName, "documents", document.DocumentId); //IndexDescriptor indexDesc = IndexDescriptor; //IndexRequestParameters indexParameter = new IndexRequestParameters(); // indexParameter.Replication(1); client.Index(document, i => i.Id(document.DocumentId).Index(indexName)); //client.Index(); //client.Index() } }
public advertisement SearchById(string adid) { // Search query // var searchResults = elasticClient.Search<Person>(s => s.From(0).Size(10).Query(q => q.Term(p => p.Lastname, "asif"))); try { List<advertisement> list = new List<advertisement>(); var connectionSettings = new ConnectionSettings(MainVariables.conElasticSearch); connectionSettings.SetDefaultIndex("advertisement"); var elasticClient = new ElasticClient(connectionSettings); QueryContainer queryById = new TermQuery() { Field = "_id", Value = adid }; var hits = elasticClient.Search<advertisement>(s => s.Query(q => q.MatchAll() && queryById)); //var searchResults = elasticClient.Search<advertisement>(s => s.Query(q => q.Term(p => "_id", adid))).Hits; list = hits.Documents.ToList(); return list[0]; } catch (Exception) { return null; } }
public List<advertisement> SearchByImageStatus() { // Search query // var searchResults = elasticClient.Search<Person>(s => s.From(0).Size(10).Query(q => q.Term(p => p.Lastname, "asif"))); try { List<advertisement> list = new List<advertisement>(); var connectionSettings = new ConnectionSettings(MainVariables.conElasticSearch); connectionSettings.SetDefaultIndex("advertisement"); var elasticClient = new ElasticClient(connectionSettings); // var response = elasticClient.Search<advertisement>(s => s.Query(q => q.MatchAll() && q.Nested(n =>n.Path("ad_details").Query(q2 => q2.Nested(n2 => n2.Path("images").Query(q3 =>q3.Term(c => c.ad_details.First().Images.First().IsServerUploaded,false))))))); var response = elasticClient.Search<advertisement>(s => s.Query(q => q.MatchAll() && q.Nested(n => n.Path("ad_details").Query(q2 => q2.Nested(n2 => n2.Path("ad_details.images").Query(q3 => q3.Term(c => c.ad_details[0].Images.First().IsServerUploaded, "true"))))))); list = response.Documents.ToList(); return list; } catch (Exception) { return null; } }
internal bool Insert(ad_network obj) { var connectionSettings = new ConnectionSettings(MainVariables.conElasticSearch); connectionSettings.SetDefaultIndex("ad_network"); var elasticClient = new ElasticClient(connectionSettings); //var indexaaa = elasticClient.DeleteIndex("advertisement"); var index = elasticClient.Index(obj); if (index.ServerError == null) return true; else return false; }
public List<websites> SelectAll() { List<string> idList = new List<string>(); List<websites> list = new List<websites>(); Dictionary<List<websites>, List < string >> dic = new Dictionary<List<websites>, List<string>>(); var connectionSettings = new ConnectionSettings(MainVariables.conElasticSearch); connectionSettings.SetDefaultIndex("websites"); connectionSettings.MapDefaultTypeNames(m => m.Add(typeof(websites), "list")); var elasticClient = new ElasticClient(connectionSettings); var searchResults = elasticClient.Search<websites>(q => q.From(0).Size(10000).MatchAll()); list = searchResults.Documents.ToList(); foreach(IHit<websites> hit in searchResults.Hits) { idList.Add(hit.Id); } for(int i=0;i<idList.Count;i++) { list[i]._id = idList[i]; } return list; }
public AdventureLocationRepository() { var setting = new ConnectionSettings("office.mtctickets.com", 9200); setting.SetDefaultIndex("pins"); client = new ElasticClient(setting); }
/// <summary> /// (re-)Index Albums /// </summary> /// <referenceUrl>https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/_nest.html</referenceUrl> /// <returns></returns> public ActionResult ReIndex() { var node = new Uri(ConfigurationManager.AppSettings["ElasticSearchUrl"] ?? "http://localhost:9200"); var esIndex = ConfigurationManager.AppSettings["ESDefaultIndex"] ?? "musicstore"; //var settings = new ConnectionSettings("localhost", 9200); //var settings = new ConnectionSettings(node, defaultIndex: esIndex); var settings = new ConnectionSettings(node); settings.SetDefaultIndex(esIndex); var client = new ElasticClient(settings); foreach (var album in db.Albums) { //client.Index(album, "musicstore", "albums", album.AlbumId); // outdated //client.Index(album, i => i.Id(album.AlbumId)) client.Index(album); // ES will infer the } return RedirectToAction("Index"); }
public List<ad_network> SelectAllwithRange(int start, int end) { // Search query // var searchResults = elasticClient.Search<Person>(s => s.From(0).Size(10).Query(q => q.Term(p => p.Lastname, "asif"))); List<ad_network> list = new List<ad_network>(); var connectionSettings = new ConnectionSettings(MainVariables.conElasticSearch); connectionSettings.SetDefaultIndex("ad_network"); var elasticClient = new ElasticClient(connectionSettings); var searchResults = elasticClient.Search<ad_network>(s => s.From(start).Size(end)); list = searchResults.Documents.ToList(); return list; }
public IElasticClient ConfigureElastic() { var connectionString = ConfigurationManager.ConnectionStrings["Elastic"]; if (connectionString == null) { throw new ArgumentException("No elastic connection string found"); } var data = connectionString.ConnectionString.Split(';'); var url = data.FirstOrDefault(x => x.StartsWith("Url", StringComparison.CurrentCultureIgnoreCase)); if (url == null) { throw new ArgumentException("No URL parameter in elastic connection string"); } var index = data.FirstOrDefault(x => x.StartsWith("DefaultIndex", StringComparison.CurrentCultureIgnoreCase)); if (index.IsNullOrEmpty()) { throw new ArgumentException("No DefaultIndex parameter in elastic connection string"); } index = index.Substring(13); var node = new Uri(url.Substring(4)); var settings = new Nest.ConnectionSettings(node); settings.SetDefaultIndex(index); settings.SetDefaultTypeNameInferrer(type => type.FullName.Replace("Demo.Application.ServiceStack.", "").Replace('.', '_')); // Disable camel case field names (need to match out POCO field names) settings.SetDefaultPropertyNameInferrer(field => field); var client = new ElasticClient(settings); if (!client.IndexExists(index).Exists) { client.CreateIndex(index, i => i .Analysis(analysis => analysis .TokenFilters(f => f .Add("ngram", new Nest.NgramTokenFilter { MinGram = 2, MaxGram = 15 }) ) .Analyzers(a => a .Add( "default_index", new Nest.CustomAnalyzer { Tokenizer = "standard", Filter = new[] { "standard", "lowercase", "asciifolding", "kstem", "ngram" } } ) .Add( "suffix", new Nest.CustomAnalyzer { Tokenizer = "keyword", Filter = new[] { "standard", "lowercase", "asciifolding", "reverse" } } ) ) )); } return(client); }
public ad_network SearchById(int id) { // Search query // var searchResults = elasticClient.Search<Person>(s => s.From(0).Size(10).Query(q => q.Term(p => p.Lastname, "asif"))); try { List<ad_network> list = new List<ad_network>(); var connectionSettings = new ConnectionSettings(MainVariables.conElasticSearch); connectionSettings.SetDefaultIndex("ad_network"); var elasticClient = new ElasticClient(connectionSettings); var searchResults = elasticClient.Search<ad_network>(s => s.Query(q => q.Term(p => p.id, id))); list = searchResults.Documents.ToList(); return list[0]; } catch (Exception) { return null; } }
public IElasticClient ConfigureElastic() { var connectionString = ConfigurationManager.ConnectionStrings["Elastic"]; if (connectionString == null) throw new ArgumentException("No elastic connection string found"); var data = connectionString.ConnectionString.Split(';'); var url = data.FirstOrDefault(x => x.StartsWith("Url", StringComparison.CurrentCultureIgnoreCase)); if (url == null) throw new ArgumentException("No URL parameter in elastic connection string"); var index = data.FirstOrDefault(x => x.StartsWith("DefaultIndex", StringComparison.CurrentCultureIgnoreCase)); if (index.IsNullOrEmpty()) throw new ArgumentException("No DefaultIndex parameter in elastic connection string"); index = index.Substring(13); var node = new Uri(url.Substring(4)); var settings = new Nest.ConnectionSettings(node); settings.SetDefaultIndex(index); settings.SetDefaultTypeNameInferrer(type => type.FullName.Replace("Demo.Application.ServiceStack.", "").Replace('.', '_')); // Disable camel case field names (need to match out POCO field names) settings.SetDefaultPropertyNameInferrer(field => field); var client = new ElasticClient(settings); if (!client.IndexExists(index).Exists) client.CreateIndex(index, i => i .Analysis(analysis => analysis .TokenFilters(f => f .Add("ngram", new Nest.NgramTokenFilter { MinGram = 2, MaxGram = 15 }) ) .Analyzers(a => a .Add( "default_index", new Nest.CustomAnalyzer { Tokenizer = "standard", Filter = new[] { "standard", "lowercase", "asciifolding", "kstem", "ngram" } } ) .Add( "suffix", new Nest.CustomAnalyzer { Tokenizer = "keyword", Filter = new[] { "standard", "lowercase", "asciifolding", "reverse" } } ) ) )); return client; }
public ad_network SearchByName(string name) { // Search query // var searchResults = elasticClient.Search<Person>(s => s.From(0).Size(10).Query(q => q.Term(p => p.Lastname, "asif"))); try { List<ad_network> list = new List<ad_network>(); var connectionSettings = new ConnectionSettings(MainVariables.conElasticSearch); connectionSettings.SetDefaultIndex("ad_network"); var elasticClient = new ElasticClient(connectionSettings); var searchResults = elasticClient.Search<ad_network>(s => s.From(0).Size(10).Query(q => q.Term(p => p.name, "Adblade"))); QueryContainer queryById = new TermQuery() { Field = "_name", Value = "Adblade" }; var hits = elasticClient.Search<ad_network>(s => s.Query(q => q.MatchAll() && queryById)); list = searchResults.Documents.ToList(); return list[0]; } catch (Exception) { return null; } }
internal bool Update(string id,string time) { var connectionSettings = new ConnectionSettings(MainVariables.conElasticSearch); connectionSettings.SetDefaultIndex("websites"); connectionSettings.MapDefaultTypeNames(m => m.Add(typeof(websites), "list")); var elasticClient = new ElasticClient(connectionSettings); var index = elasticClient.Update<websites, object>(u => u .Id(id) .Doc(new {last_run=DateTime.Now, Scrapping_Time=time }) .RetryOnConflict(3) .Refresh() ); // var index = elasticClient.Update<websites, object>(u => u .IdFrom(obj).Doc(new { website_url = "United States" }).DocAsUpsert()); // var index = elasticClient.Index(obj); //var index= elasticClient.Update<websites, object>(u => u.Upsert(new websites { _id = "AVFX2hdEYZh0OvPHWO7l", website_url = "http://www.google.com" })); if (index.ServerError == null && index.ConnectionStatus.HttpStatusCode.Value < 203) return true; else return false; }
public ActionResult ReIndexAll() { var documents = db.DocumentModels.ToList(); var uriString = ConfigurationManager.AppSettings["SEARCHBOX_URL"]; var searchBoxUri = new Uri(uriString); var settings = new ConnectionSettings(searchBoxUri); settings.SetDefaultIndex(indexName); var client = new ElasticClient(settings); // delete index if exists at startup if (client.IndexExists(indexName).Exists) { client.DeleteIndex(indexName); } // Create a new "sample" index with default settings //client.CreateIndex("sample", new IndexSettings()); ICreateIndexRequest iCreateIndexReq = new CreateIndexRequest(indexName); iCreateIndexReq.IndexSettings = new IndexSettings(); iCreateIndexReq.IndexSettings.NumberOfReplicas = 10; //client.CreateIndex(iCreateIndexReq); var resCreate = client.CreateIndex(indexName, s => s.AddMapping<DocumentModel>(f => f.MapFromAttributes()).NumberOfReplicas(1).NumberOfShards(10)); //client.CreateIndex() // Index all documents client.IndexMany<DocumentModel>(documents); //client.Index() ViewBag.Message = "Reindexing all database is complete!"; return RedirectToAction("Index"); }
internal bool Update(ad_network obj) { var connectionSettings = new ConnectionSettings(MainVariables.conElasticSearch); connectionSettings.SetDefaultIndex("ad_network"); var elasticClient = new ElasticClient(connectionSettings); var index = elasticClient.Index(obj); if (index.ServerError == null && !index.Created && index.ConnectionStatus.HttpStatusCode.Value < 203) return true; else return false; }
private static void Index(Document document, String operation) { var uriString = ConfigurationManager.AppSettings["SEARCHBOX_URL"]; var searchBoxUri = new Uri(uriString); var settings = new ConnectionSettings(searchBoxUri); settings.SetDefaultIndex("sample"); var client = new ElasticClient(settings); if (operation.Equals("delete")) { ConnectionStatus status = client.DeleteById("sample", "documents", document.DocumentId); } else { client.Index(document, "sample", "documents", document.DocumentId); } }
public bool Delete(string id) { var connectionSettings = new ConnectionSettings(MainVariables.conElasticSearch); connectionSettings.SetDefaultIndex("websites"); connectionSettings.MapDefaultTypeNames(m => m.Add(typeof(websites), "list")); var elasticClient = new ElasticClient(connectionSettings); return elasticClient.Delete(new Nest.DeleteRequest("websites", "list", id)).Found; }
private static void Index(Document document, String operation) { var uriString = ConfigurationManager.AppSettings["SEARCHBOX_URL"]; var searchBoxUri = new Uri(uriString); var settings = new ConnectionSettings(searchBoxUri); settings.SetDefaultIndex("sample"); var client = new ElasticClient(settings); if (!client.IndexExists("sample").Exists) { // Create a new "sample" index with default settings client.CreateIndex("sample", new IndexSettings()); } if (operation.Equals("delete")) { client.DeleteById("sample", "documents", document.DocumentId); } else { client.Index(document, "sample", "documents", document.DocumentId); } }
public List<ad_network> SelectAll() { List<ad_network> list = new List<ad_network>(); var connectionSettings = new ConnectionSettings(MainVariables.conElasticSearch); connectionSettings.SetDefaultIndex("ad_network"); var elasticClient = new ElasticClient(connectionSettings); var searchResults = elasticClient.Search<ad_network>(s => s.Query(q => q.MatchAll())); list = searchResults.Documents.ToList(); return list; }
public ActionResult ReIndexAll() { var documents = db.Documents.ToList(); var uriString = ConfigurationManager.AppSettings["SEARCHBOX_URL"]; var searchBoxUri = new Uri(uriString); var settings = new ConnectionSettings(searchBoxUri); settings.SetDefaultIndex("sample"); var client = new ElasticClient(settings); // delete index if exists at startup if (client.IndexExists("sample").Exists) { client.DeleteIndex("sample"); } // Create a new "sample" index with default settings client.CreateIndex("sample", new IndexSettings()); // Index all documents client.IndexMany<Document>(documents); ViewBag.Message = "Reindexing all database is complete!"; return RedirectToAction("Index"); }