public string CreateUser(User user) { if (user == null) { throw new ArgumentNullException("user"); } if (String.IsNullOrEmpty(user.Id)) { user.Id = GenerateUniqueId(user); } var response = GetClient().Index(user, index, new IndexParameters() { Refresh = true }); return response.Id; }
public List<User> GetUsers(string criteria) { if (String.IsNullOrEmpty(criteria)) { criteria = "*"; } var response = GetClient().IndexExists(index); if (!response.Exists) { GetClient().CreateIndex(index, new IndexSettings()); var user = new User { Id = "dsandron", city = "Bankok", name = "Danilo" }; GetClient().Index(user, index, new IndexParameters() { Refresh = true }); user = new User { Id = "rlouapre", city = "Jersey City", name = "Richard" }; GetClient().Index(user, index, new IndexParameters() { Refresh = true }); } var results = GetClient().Search<User>(body => body.Query(query => query.QueryString(qs => qs.Query(criteria)))); Console.WriteLine("Query: {0} - results total: {1}", criteria, results.Total); return results.Documents.ToList(); }
private void CreateUser(ref User user) { DocumentService service = new DocumentService(); string id = service.CreateUser(user); user.Id = id; }
private string GenerateUniqueId(User user) { return Guid.NewGuid().ToString(); }