Advertisement
Umineko

Untitled

Aug 7th, 2014
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.52 KB | None | 0 0
  1. using System;
  2. using Nest;
  3.  
  4. namespace ConsoleApplication2
  5. {
  6.     class Program
  7.     {
  8.         class Document
  9.         {
  10.             public string Field1 { get; set; }
  11.             public string Field2 { get; set; }
  12.  
  13.             public override string ToString()
  14.             {
  15.                 return string.Format("{{ Field1: '{0}', Field2: '{1}' }}", Field1, Field2);
  16.             }
  17.         }
  18.  
  19.         static void Main(string[] args)
  20.         {
  21.             var elasticClient = new ElasticClient(new ConnectionSettings(new Uri("http://localhost:9200"), "test"));
  22.  
  23.             elasticClient.Index(new Document { Field1 = "Value1", Field2 = "Value2" }, s => s.Id("123"));
  24.  
  25.             var response = elasticClient.GetMany<Document>(new[] { "123" });
  26.  
  27.             var response2 = elasticClient.MultiGet(s => s.GetMany<Document>(new[] { "123" }));
  28.  
  29.             Console.WriteLine("First result");
  30.             foreach (var hit in response)
  31.             {
  32.                 Console.WriteLine("Found document with id {0}? {1}", hit.Id, hit.Found ? "Yes" : "No");
  33.                 if (hit.Found)
  34.                     Console.WriteLine(hit.Source);
  35.             }
  36.  
  37.             Console.WriteLine("Second result");
  38.             foreach (var hit in response2.Documents)
  39.             {
  40.                 Console.WriteLine("Found document with id {0}? {1}", hit.Id, hit.Found ? "Yes" : "No");
  41.                 if (hit.Found)
  42.                     Console.WriteLine(hit.Source);
  43.             }
  44.  
  45.             Console.ReadKey(false);
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement