static void indexerDemandeurs() { using (var db = new anemContext()) { var demandeurs = db.Demandeurs .ProjectTo <VmDemandeur>() .OrderBy(x => x.Id) .Skip(200000) .Take(1000) .ToList(); int i = 0; foreach (var demandeur in demandeurs) { i++; Console.WriteLine($"Id : {demandeur.Id} nom : {demandeur.Nom} "); var IndexResponse = ElasticClient. Index <string>("demandeurs", "demandeur", demandeur.Id, demandeur); //Stream responseString = IndexResponse.Body; if (i % 20 == 0) { Console.WriteLine($"ordre : {i} Status : {IndexResponse.HttpStatusCode} "); } } } }
private void UpdateNodeRun() { try { while (true) { while (!_addDocumentQueue.IsEmpty) { object[] addedDocument; if (_addDocumentQueue.TryPeek(out addedDocument)) { var path = (string)addedDocument[0]; if (_elasticClient.IndexExists(path).Exists) { _addDocumentQueue.TryTake(out addedDocument); INode node = addedDocument[1] as INode; var jObject = node.ToJObject(); //_elasticClient.Index(jObject.ToString(Newtonsoft.Json.Formatting.None), // i => i.Index((string) addedDocument[0]).Id(Guid.NewGuid().ToString())); _elasticLowLevelClient.Index <BytesResponse>(path, node.GroupName, PostData.String(jObject.ToString())); } } } } } catch (Exception ex) { } }
public static void LoadPersonDataIntoIndex(List <Person> data) { foreach (var person in data) { var body = PostData.Serializable(person); var response = lowlevelClient.Index <StringResponse>(indexName, "person", person.Id, body); var responseString = response.Body; } }
//public bool SaveList(List<Person> lstToSave) public bool SaveList(dynamic lst) { foreach (var item in lst) { var ndexResponse = elastic.Index <BytesResponse>(_index, item.Id, PostData.Serializable(item)); byte[] responseBytes = ndexResponse.Body; } return(true); }
/// <summary> /// 插入文档 /// </summary> /// <param name="index"></param> /// <param name="type"></param> /// <param name="doc"></param> public bool InsertDocument(string index, string type, string id, BsonDocument doc) { bool flag = false; StringResponse resStr = null; try { resStr = client.Index <StringResponse>(index, type, id, PostData.String(doc.ToJson(new JsonWriterSettings { OutputMode = JsonOutputMode.Strict }))); var resObj = JObject.Parse(resStr.Body); if ((int)resObj["_shards"]["successful"] > 0) { flag = true; } else { LogUtil.LogInfo(logger, resStr.DebugInformation, nodeId); } } catch (Exception ex) { if (resStr != null) { LogUtil.LogInfo(logger, resStr.DebugInformation, nodeId); } LogUtil.LogError(logger, ex.ToString(), nodeId); } return(flag); }
private void cmdInsert_Click(object sender, EventArgs e) { var settings = new ConnectionConfiguration(EndPoint()) .RequestTimeout(TimeSpan.FromMinutes(2)); var lowlevelClient = new ElasticLowLevelClient(settings); var person = new Person { firstName = "David", lastName = "Betteridge" }; var indexResponse = lowlevelClient.Index <BytesResponse>("people", "person", "David", PostData.Serializable(person)); var responseBytes = indexResponse.Body; txtResult.Text = PrettyPrintJSON(BytesToString(responseBytes)); /************************************************************************************************ * We can also get the result in string format \/ *************************************************************************************************/ //var indexResponse = lowlevelClient.Index<StringResponse>("people", "person", "David", PostData.Serializable(person)); //var responseString = indexResponse.Body; //txtResult.Text = PrettyPrintJSON(responseString); }
public static void MainMethod() { try { //var lowlevelClient = new ElasticLowLevelClient(); var settings = new ConnectionConfiguration(new Uri("http://120.27.213.67:9200")).RequestTimeout(TimeSpan.FromMinutes(2)); //var lowlevelClient = new ElasticLowLevelClient(settings); //var uris = new[]{new Uri("http://120.27.213.67:9200"),}; //var connectionPool = new SniffingConnectionPool(uris); //var settings = new ConnectionConfiguration(connectionPool); var lowlevelClient = new ElasticLowLevelClient(settings); var person = new Person { FirstName = "Martijn", LastName = "Laarman" }; var indexResponse = lowlevelClient.Index <StringResponse>("people", "person", "1", PostData.Serializable(person)); string responseBytes = indexResponse.Body; //var asyncIndexResponse = await lowlevelClient.IndexAsync<StringResponse>("people", "person", "1", PostData.Serializable(person)); //string responseString = asyncIndexResponse.Body; } catch (Exception ex) { throw ex; } }
static async Task Main(string[] args) { // var lowlevelClient = new ElasticLowLevelClient(); var settings = new ConnectionConfiguration(new Uri("http://localhost:9200")).RequestTimeout(TimeSpan.FromMinutes(2)); var lowlevelClient = new ElasticLowLevelClient(settings); // var uris = new [] // { // new Uri("http://es01:9200"), // new Uri("http://es02:9201"), // new Uri("http://es03:9202"), // }; // var connectionPool = new SniffingConnectionPool(uris); // var settings = new ConnectionConfiguration(connectionPool); // var lowlevelClient = new ElasticLowLevelClient(settings); var person = new Person { FirstName = "Will", LastName = "Laarman" }; var ndexResponse = lowlevelClient.Index <BytesResponse>("people", "1", PostData.Serializable(person)); byte[] responseBytes = ndexResponse.Body; Console.WriteLine(); Console.WriteLine(System.Text.Encoding.UTF8.GetString(responseBytes)); Console.WriteLine(); var asyncIndexResponse = await lowlevelClient.IndexAsync <StringResponse>("people", "1", PostData.Serializable(person)); string responseString = asyncIndexResponse.Body; var searchResponse = lowlevelClient.Search <StringResponse>("people", PostData.Serializable(new { from = 0, size = 10, query = new { match = new { firstName = new { query = "Will" } } } })); var successful = searchResponse.Success; var successOrKnownError = searchResponse.SuccessOrKnownError; var exception = searchResponse.OriginalException; var responseJson = searchResponse.Body; Console.WriteLine(responseJson); }
public virtual void Index(string indexName, IIndexableItem item) { if ((item.TimeToLive.HasValue && item.TimeToLive >= DateTime.Now) || !item.TimeToLive.HasValue) { var indexResponse = Client.Index <BytesResponse>(indexName, item.Type, item.Id.ToString(), PostData.Serializable(item.ToDictionary())); var resp = Encoding.UTF8.GetString(indexResponse.Body); } }
public ResultWrapper <T> AddOrUpdate <T>(string index, string type, string id, T body) where T : class { var response = _clusterClient.Index <T>(index, type, id, new PostData <T>(body)); var result = Request <T, T>(response, (r) => response.Body); return(result); }
private static void IndexLowLevel(string jsonBody) { var settings = new ConnectionConfiguration(new Uri("http://localhost:9200")).RequestTimeout(TimeSpan.FromMinutes(2)); var lowlevelClient = new ElasticLowLevelClient(settings); var indexResponse = lowlevelClient.Index <BytesResponse>("outlook", "doc", PostData.String(jsonBody)); byte[] responseBytes = indexResponse.Body; CommonComponents_NETStandard.Globals.logger.CreateOrAppend(responseBytes.ToString()); }
public string dosomething(string esUrl) { var node = new Uri(esUrl); var config = new ConnectionConfiguration(node); var client = new ElasticLowLevelClient(config); //return client.GetSource<string>("movies", "movie", "AVpLSOrF6ryMWCw3ykHv").Body; var myJson = new { hello = "world" }; return(client.Index <string>("movies", "movie", "2", myJson).Body); }
static void Test() { var nodes = new Uri[] { new Uri("http://10.204.124.222:9200"), }; var pool = new StaticConnectionPool(nodes); var settings = new ConnectionSettings(pool).DefaultIndex("photo_album_image"); var client = new ElasticClient(settings); var lowLevelClient = new ElasticLowLevelClient(settings); var data = new ImageModel { Description = " 说明 ", CreateTime = DateTime.Now, Filename = "filename.jpng", KeyWorld = new System.Collections.Generic.List <string> { "test" }, Id = Guid.NewGuid().ToString(), Location = "shengzheng", Subject = "有望", Videos = "test.mp4" }; var ndexResponse = lowLevelClient.Index <ImageModel>("索引", "PostData", PostData.Serializable(data)); var searchResponse = lowLevelClient.Search <StringResponse>("people", PostData.Serializable(new { from = 0, size = 10, query = new { match = new { firstName = new { query = "Martijn" } } } })); var successful = searchResponse.Success; var responseJson = searchResponse.Body; var response = client.IndexDocument(data); var t = response.Result; var searchReponse = client.Search <ImageModel>(s => s.From(0).Size(10).Query(q => q. Match(m => m.Field(f => f.Filename).Query("filename.jpng")))); var people = searchReponse.Documents; }
/// <summary> /// Index document. /// </summary> /// <param name="type">Type name.</param> /// <param name="documentIdentifier">Unique document identifier.</param> /// <param name="documentJson">Document in JSon format.</param> protected void Index(String type, String documentIdentifier, String documentJson) { ElasticsearchResponse <DynamicResponse> response; response = _client.Index <DynamicResponse>(IndexName, type, documentIdentifier, documentJson); CheckResponse(response); }
static void Indexing() { var person = new Person { FirstName = "Martijn", LastName = "Laarman" }; var indexResponse = client.Index <BytesResponse>("people", "person", "1", PostData.Serializable(person)); byte[] responseBytes = indexResponse.Body; }
static public void SendItemToDiscord(XmlNode item) { // set discord webhook as private env string webhook = Environment.GetEnvironmentVariable("DISCORD_WEBHOOK"); string esInstance = Environment.GetEnvironmentVariable("ES_INSTANCE"); if (webhook == null) { Console.WriteLine("GET A DISCORD WEBHOOK"); return; } var request = (HttpWebRequest)WebRequest.Create(webhook); request.ContentType = "application/json"; request.Method = "POST"; DateTime pubDate = Convert.ToDateTime(item["pubDate"].InnerText); string postLink = item["link"].InnerText; string discordTemplate = "{0} \n {1} \n {2} "; string discordMessage = string.Format(discordTemplate, item["title"].InnerText, item["pubDate"].InnerText, postLink); // write message of data sent to discord var w = new WebhookData() { content = discordMessage }; using (var streamWriter = new StreamWriter(request.GetRequestStream())) { streamWriter.Write(JsonSerializer.Serialize <WebhookData>(w)); } var httpResponse = (HttpWebResponse)request.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var result = streamReader.ReadToEnd(); } // send data to es instance var settings = new ConnectionConfiguration(new Uri(esInstance)) .RequestTimeout(TimeSpan.FromMinutes(2)); var lowlevelClient = new ElasticLowLevelClient(settings); var post = new Post { guid = item["guid"].InnerText }; var asyncIndexResponse = lowlevelClient.Index <StringResponse>("post", PostData.Serializable(post)); string responseString = asyncIndexResponse.Body; Console.WriteLine(responseString); }
public Notice Add(AdminUser user) { Notice notice = new Notice(); try { var settings = new ConnectionConfiguration(new Uri("http://localhost:9200/")) .RequestTimeout(TimeSpan.FromMinutes(2)); var lowlevelClient = new ElasticLowLevelClient(settings); /*var people = new object[] * { * new { index = new { _index = "people", _type = "person", _id = "1" }}, * new { FirstName = "Martijn", LastName = "Laarman" }, * new { index = new { _index = "people", _type = "person", _id = "2" }}, * new { FirstName = "Greg", LastName = "Marzouka" }, * new { index = new { _index = "people", _type = "person", _id = "3" }}, * new { FirstName = "Russ", LastName = "Cam" }, * }; * * var indexResponse = lowlevelClient.Bulk<Stream>(people); * Stream responseStream = indexResponse.Body;*/ //var person = new Models.Person //{ // FirstName = "Martijn", // LastName = "Laarman" //}; //lowlevelClient.de var indexResponse = lowlevelClient.Index <byte[]>("user", "guest", user.Id.ToString(), user); byte[] responseBytes = indexResponse.Body; notice = new Notice { Result = true, Message = "创建成功!" }; } catch (ElasticsearchClientException ex) { notice = new Notice { Result = false, Message = ex.Message }; } return(notice); }
public static void IndexLab(ElasticLowLevelClient lowlevelClient) { var person = new Person { Id = 1, Name = "Jack" }; var indexResponse = lowlevelClient.Index <BytesResponse>("people", "person", "1", PostData.Serializable(person)); byte[] responseBytes = indexResponse.Body; var asyncIndexResponse = lowlevelClient.IndexAsync <StringResponse>("people", "person", "1", PostData.Serializable(person)).GetAwaiter().GetResult(); string responseString = asyncIndexResponse.Body; Console.WriteLine(responseString); }
static void index(ElasticLowLevelClient client) { var person = new Person { FirstName = "Monique", LastName = "Wink James" }; //Synchronous methods, returns IIndexResponse var indexResponse = client.Index <byte[]>("people", "person", "1", person); byte[] responseBytes = indexResponse.Body; Console.WriteLine("Index response: {0}", indexResponse); //Asynchronous method, returns Task<IIndexResponse> //var asyncIndexResponse = await client.IndexAsync<string>("people", "person", "1", person); //string responseString = asyncIndexResponse.Body; //Console.WriteLine("Index response: {0}", responseString); }
public JsonResult Create(int id, string realname, string phone, string description) { var oResult = new Object(); try { AdminUser user = new AdminUser { Id = id, Account = realname, RealName = realname, Phone = phone, Description = description, CreateTime = DateTime.Now, ModifyTime = DateTime.Now }; var settings = new ConnectionConfiguration(new Uri("http://localhost:9200/")) .RequestTimeout(TimeSpan.FromMinutes(2)); var lowlevelClient = new ElasticLowLevelClient(settings); var indexResponse = lowlevelClient.Index <byte[]>("user", "guest", user.Id.ToString(), user); byte[] responseBytes = indexResponse.Body; oResult = new { Result = true, Message = "创建成功!" }; } catch (ElasticsearchClientException ex) { oResult = new { Result = true, Message = "创建失败!" }; } return(Json(oResult, JsonRequestBehavior.AllowGet)); }
public void IndexerDemandeurs() { var take = 5000; var Count = 2000000; var Start = Properties.Settings.Default.start; using (var context = new FNE()) { //var Count = context.Demandeurs.Count(); int Current = Start; while (Start <= Count) { var demandeurs = context.Demandeurs .Where(d => d.DateDebutContrat.HasValue) .OrderBy(x => x.id) .Skip(Start) .Take(take) .ToList(); foreach (var demandeur in demandeurs) { Current++; var IndexResponse = ElasticClient. Index <string>("demandeurs", "demandeurs", demandeur.id, demandeur); //Stream responseString = IndexResponse.Body; OnLog(new LogEventArgs($" N° : {Current} Status : {IndexResponse.HttpStatusCode} Id : {demandeur.id} Nom : {demandeur.Nom} {demandeur.Prenom}")); } Start += take; } } }
public async Task <IActionResult> GetResponseByFeedbackId(string feedbackId) { /*_equipmentGroup.*/ //get questionId from feedbackId List <Question> listQuestion = _questionRepository.GetAll().ToList <Question>(); List <Question> listQuestionForFb = new List <Question>(); List <string> listQuestionId = new List <string>(); List <ResponseModel> listResponse = new List <ResponseModel>(); List <Response> listTmp = new List <Response>(); List <ResponseModel> listResForOneQues = new List <ResponseModel>(); List <List <ResponseModel> > listResult = new List <List <ResponseModel> >(); foreach (Question que in listQuestion) { if (que.FeedbackId.Equals(feedbackId)) { listQuestionId.Add(que.QuestionId); listQuestionForFb.Add(que); } } //get all response from QuestionID for (int questionIndex = 0; questionIndex < listQuestionId.Count; questionIndex++) { listTmp = _responseRepository.GetResponseByQuestionId(listQuestionId[questionIndex]).ToList(); foreach (Response r in listTmp) { String tmpResponseDetail = r.ResponseDetail; List <string> listResponseDetail = new List <string>(); //TypeOfQuestion 1: Emotion if (r.Question.TypeOfQuestion == 1) { switch (tmpResponseDetail) { case "1": tmpResponseDetail = "Thất vọng"; break; case "2": tmpResponseDetail = "Tạm ổn"; break; case "3": tmpResponseDetail = "Tốt"; break; case "4": tmpResponseDetail = "Tuyệt vời"; break; case "5": tmpResponseDetail = "Yêu thích"; break; } } //TypeOfQuestion 2: Rating star else if (r.Question.TypeOfQuestion == 2) { tmpResponseDetail = r.ResponseDetail.Substring(0, 1) + " sao"; } else if (r.Question.TypeOfQuestion == 3) { listResponseDetail = getResponseDetail(r.ResponseDetail); foreach (string detail in listResponseDetail) { ResponseModel resModelForMultichoice = new ResponseModel { equipmentId = r.EquipmentId, questionId = questionIndex + "", responseDetail = detail, typeOfQuestion = r.Question.TypeOfQuestion + "", responseTime = r.ResponseTime }; listResponse.Add(resModelForMultichoice); } } //TypeOfQuestion 4: one choice else if (r.Question.TypeOfQuestion == 4) { tmpResponseDetail = r.ResponseDetail; } if (r.Question.TypeOfQuestion != 3) { ResponseModel resModel = new ResponseModel { equipmentId = r.EquipmentId, questionId = questionIndex + "", responseDetail = tmpResponseDetail, typeOfQuestion = r.Question.TypeOfQuestion + "", responseTime = r.ResponseTime }; listResponse.Add(resModel); if (questionIndex == 0) { listResForOneQues.Add(resModel); } } } listResult.Add(listResponse); } var settings = new ConnectionConfiguration(new Uri("http://localhost:9200")) .RequestTimeout(TimeSpan.FromMinutes(2)); var lowlevelClient = new ElasticLowLevelClient(settings); //push data on elastic for count response of feedback int i = 0; int checkIdOfIndexExist = 0; if (HttpContext.Session.GetInt32("TotalIdIndexOfCountRes") != null) { checkIdOfIndexExist = (int)HttpContext.Session.GetInt32("TotalIdIndexOfCountRes"); if (checkIdOfIndexExist != 0) { //Clear all data in index for (int j = 1; j <= checkIdOfIndexExist; j++) { lowlevelClient.Delete <StringResponse>("countresponseforfb", Convert.ToString(j)); } HttpContext.Session.Remove("TotalIdIndexOfCountRes"); } } foreach (ResponseModel res in listResForOneQues) { lowlevelClient.Index <StringResponse>("countresponseforfb", Convert.ToString(++i), PostData.Serializable(res)); } HttpContext.Session.SetInt32("TotalIdIndexOfCountRes", i); //Id cho tung object trong index #region push response on elastic i = 0; checkIdOfIndexExist = 0; if (HttpContext.Session.GetInt32("TotalIdIndex") != null) { checkIdOfIndexExist = (int)HttpContext.Session.GetInt32("TotalIdIndex"); if (checkIdOfIndexExist != 0) { //Clear all data in index for (int j = 1; j <= checkIdOfIndexExist; j++) { lowlevelClient.Delete <StringResponse>("testresponse", Convert.ToString(j)); } HttpContext.Session.Remove("TotalIdIndex"); } } foreach (ResponseModel res in listResponse) { lowlevelClient.Index <StringResponse>("testresponse", Convert.ToString(++i), PostData.Serializable(res)); } HttpContext.Session.SetInt32("TotalIdIndex", i); #endregion ViewBag.countResponse = listResForOneQues.Count; ViewBag.listQuestion = listQuestionForFb; ViewBag.feedbackId = feedbackId; getFeedbackIDByBrandId(); getEquipmentGroupId(); await HttpContext.Session.LoadAsync(); HttpContext.Session.SetString("feedbackId", feedbackId); await HttpContext.Session.CommitAsync(); EquipmentGroup e = new EquipmentGroup { EquipmentGroupId = HttpContext.Session.GetString("equipmentGroupId") }; await GetListFeedbackByEquipmentGroupId(e); return(View("Admin")); }
public void Save(Person p) { var indexResponse = _elasticLowLevelClient.Index <StringResponse>("people", "person", PostData.Serializable(p)); Console.WriteLine(indexResponse.Body); }
public void OutputEntry(T retrievedInfo) { var indexResponse = lowlevelClient .Index <BytesResponse>(index, mapping, PostData.Serializable(retrievedInfo)); var response = indexResponse.Body; }
public void CreateDoc(string index, string type, T docType) { string json = JsonConvert.SerializeObject(docType); PostData <object> jsonPostData = new PostData <object>(json); var results = _elasticsearchClient.Index <object>(index, type, jsonPostData); }
public void Index(string indexName, IIndexableItem item) { var indexResponse = Client.Index <BytesResponse>(indexName, item.Type, item.Id.ToString(), PostData.Serializable(item.ToDictionary())); var resp = Encoding.UTF8.GetString(indexResponse.Body); }