public static async Task<bool> AddOrUpdateLocationAsync(string id, double lat, double lon) { var result = await _client.SearchAsync<ComplexLocation>(s => s.Query(q => q.QueryString(ss => ss.Query("Id:" + id)))); ComplexLocation l = null; if(result.Total >= 1) { string _id = result.Hits.First().Id; var r = await _client.UpdateAsync<ComplexLocation>((u) => { u.Id(_id); l = new ComplexLocation() { Id = id, Coordinate = new ComplexLocationCoordinate() { Lat = lat, Lon = lon }, TimeStamp = DateTime.Now.ToString(), IsBusiness = result.Documents.First().IsBusiness, Gender = result.Documents.First().Gender, ResearchFieldId = result.Documents.First().ResearchFieldId }; u.Doc(l); u.Index(_config.IndexName); return u; }); return r.IsValid; } else { l = new ComplexLocation() { Id = id, Coordinate = new ComplexLocationCoordinate() { Lon = lon, Lat = lat, }, TimeStamp = DateTime.Now.ToString(), IsBusiness = 1, Gender = 0, ResearchFieldId = 0 }; List<ComplexLocation> list = new List<ComplexLocation>() { l }; var resoponse = await _client.IndexAsync<ComplexLocation>(l, (i) => { i.Index(_config.IndexName); return i; }); return resoponse.Created; } }
public static async Task<bool> UpdateComplexLocationAsync(string id, int isBusiness, int gender, long researchfieldId) { var result = await _client.SearchAsync<ComplexLocation>(s => s.Query(q => q.QueryString(ss => ss.Query("Id:" + id)))); ComplexLocation l = null; if(result.Total >= 1) { if(isBusiness != result.Documents.First().IsBusiness || gender != result.Documents.First().Gender || researchfieldId != result.Documents.First().ResearchFieldId) { string _id = result.Hits.First().Id; var r = await _client.UpdateAsync<ComplexLocation>((u) => { u.Id(_id); l = new ComplexLocation() { Id = id, Coordinate = new ComplexLocationCoordinate() { Lat = result.Documents.First().Coordinate.Lat, Lon = result.Documents.First().Coordinate.Lon }, TimeStamp = DateTime.Now.ToString(), IsBusiness = isBusiness, Gender = gender, ResearchFieldId = researchfieldId }; u.Doc(l); u.Index(_config.IndexName); BKLogger.LogInfoAsync(typeof(ComplexLocationManager), "更新位置复杂信息:" + id + isBusiness + gender + researchfieldId); return u; }); return r.IsValid; } else return true; } else return false; }
public static bool AddOrUpdateLocation(string id, double lat, double lon) { var result = _client.Search<ComplexLocation>(s => s.Query(q => q.QueryString(ss => ss.Query("Id:" + id)))); ComplexLocation l = null; if (result.Total >= 1) { string _id = result.Documents.First().Id; var r = _client.Update<ComplexLocation>((u) => { u.Id(_id); result.Documents.First().Coordinate = new ComplexLocationCoordinate() { Lat = lat, Lon = lon }; result.Documents.First().TimeStamp = DateTime.Now.ToString(); //l = new ComplexLocation() { Id = id, Coordinate = new ComplexLocationCoordinate() { Lat = lat, Lon = lon }, TimeStamp = DateTime.Now.ToString() }; //u.Doc(l); u.Doc(result.Documents.First()); u.Index(_config.IndexName); return u; }); return r.IsValid; } else { l = new ComplexLocation() { Id = id, Coordinate = new ComplexLocationCoordinate() { Lon = lon, Lat = lat, }, TimeStamp = DateTime.Now.ToString() }; List<ComplexLocation> list = new List<ComplexLocation>() { l }; var resoponse = _client.Index(l, (i) => { i.Index(_config.IndexName); return i; }); return resoponse.Created; } }