public Food SearchFood(int Id,Food food) { var ES_Search = ESclient.Search<Food>(Id, x => x .SuggestSize(100) .AddQueryString("food", food.Name) // .AllowNoIndices(false) ); return ES_Search.Response; }
static void PostFood(Food food) { using (var client = new WebClient()) { client.Headers[HttpRequestHeader.ContentType] = "application/json"; var uri = new Uri("http://localhost:3401/api/foodapi/"); using (var stream = client.OpenWrite(uri, "POST")) { var serializer = new DataContractJsonSerializer(typeof(Food)); serializer.WriteObject(stream, food); stream.Close(); } } }
static void Main(string[] args) { Console.WriteLine("Press any key to start..."); Console.ReadKey(); Food foodie = new Food { Id = "1", Name = "Ovacado", Type = "fruit" }; PostFood(foodie); Console.WriteLine("Id:{0} Name:{1} Type:{2}", foodie.Id, foodie.Name, foodie.Type); GetFood("1"); SearchFood("fruit"); Console.WriteLine("Press any key to exit..."); Console.ReadKey(); }
public void PostFood(Food food) { var response = ESclient.Index<Food>("food",food.Type,food.Name,food.Id); redDB.StringSet(food.Id, food.Name); }