private static void IndexTweet(Tweet tweet, string id, ElasticConnection connection, JsonNetSerializer serializer) { /* $ curl -XPUT 'http://localhost:9200/twitter/tweet/1?pretty=true' -d '{ "User" : "testUser", "Message" : "trying out Elastic Search" }' */ // This is url that will be requested from ES. We can grab it and put to any ES admin console (like ElasticHead) to debug ES behavior. string indexCommand = Commands.Index(index: "twitter", type: "tweet", id: id) .Refresh(true) .Pretty(); // this will generate: twitter/tweet/1?pretty=true // This variable contains JSON of serialized tweet, thus we can check if our object serialized correctly // or use it directly in ES admin console. string tweetJson = serializer.ToJson(tweet); var result = connection.Put(indexCommand, tweetJson); // Parse index result. IndexResult indexResult = serializer.ToIndexResult(result); PrintIndexCommand(result, indexResult, indexCommand, tweetJson); }
public void Execute() { Console.WriteLine("PLAIN SAMPLE"); var connection = new ElasticConnection("localhost", 9200); var serializer = new JsonNetSerializer(); var tweet = new Tweet { User = "******", Message = "trying out Elastic Search" }; var anotherTweet = new Tweet { User = "******", Message = "one more message" }; IndexTweet(tweet, "1", connection, serializer); IndexTweet(anotherTweet, "2", connection, serializer); GetTweet("1", serializer, connection); SearchTweets(connection, serializer); DeleteTweeterIndex(connection, serializer); Console.WriteLine("Press any key"); Console.ReadKey(); }
public void Execute() { Console.WriteLine("CLIENT SAMPLE"); var client = new ElasticClient<Tweet>(defaultHost: "localhost", defaultPort: 9200); var firstTweet = new Tweet { User = "******", Message = "trying out Elastic Search" }; var anotherTweet = new Tweet { User = "******", Message = "one more message" }; IndexResult indexResult1 = client.Index(new IndexCommand(index: "twitter", type: "tweet", id: "1").Refresh(), firstTweet); IndexResult indexResult2 = client.Index(Commands.Index(index: "twitter", type: "tweet", id: "2").Refresh(), anotherTweet); GetResult<Tweet> getResult = client.Get(new GetCommand(index: "twitter", type: "tweet", id: "2")); SearchResult<Tweet> searchResult = client.Search(new SearchCommand("twitter", "tweet"), new QueryBuilder<Tweet>() .Query(q => q .Term(t => t .Field(tweet => tweet.User) .Value("testUser") .Boost(2) ) )); DeleteResult deleteResult = client.Delete(Commands.Delete(index: "twitter")); PrintIndexResult(indexResult1); PrintIndexResult(indexResult2); PrintGetResult(getResult); PrintSearchResults(searchResult); PrintDeleteResult(deleteResult); Console.WriteLine("Press any key"); Console.ReadKey(); }
private static void PrintGetCommand(Tweet getTweet, OperationResult result, string getCommand) { Console.WriteLine("Executed: \r\nGET {0} \r\n".F(getCommand)); Console.WriteLine("Get Result: \r\n {0} \r\n".F(result.Result.BeautifyJson())); Console.WriteLine("Parsed Get Result: "); Console.WriteLine(" User: "******" Message: " + getTweet.Message); Console.WriteLine(); }
public void Execute() { Console.WriteLine("CLIENT SAMPLE"); var client = new ElasticClient<Tweet>(defaultHost: "localhost", defaultPort: 9200); var firstTweet = new Tweet { User = "******", Message = "trying out Elastic Search" }; var anotherTweet = new Tweet { User = "******", Message = "one more message" }; var indexSettings = new IndexSettingsBuilder() .NumberOfShards(8) .NumberOfReplicas(1) .Analysis(analysis => analysis .Analyzer(analyzer => analyzer .Custom("keyword_lowercase", custom => custom .Tokenizer(DefaultTokenizers.keyword) .Filter(DefaultTokenFilters.lowercase)))); client.CreateIndex(new IndexCommand(index: "twitter").Refresh(), indexSettings); IndexResult indexResult1 = client.Index(new IndexCommand(index: "twitter", type: "tweet", id: "1").Refresh(), firstTweet); IndexResult indexResult2 = client.Index(Commands.Index(index: "twitter", type: "tweet", id: "2").Refresh(), anotherTweet); GetResult<Tweet> getResult = client.Get(new GetCommand(index: "twitter", type: "tweet", id: "2")); SearchResult<Tweet> searchResult = client.Search(new SearchCommand("twitter", "tweet"), new QueryBuilder<Tweet>() .Query(q => q .Term(t => t .Field(tweet => tweet.User) .Value("testUser") .Boost(2) ) )); DeleteResult deleteResult = client.Delete(Commands.Delete(index: "twitter")); PrintIndexResult(indexResult1); PrintIndexResult(indexResult2); PrintGetResult(getResult); PrintSearchResults(searchResult); PrintDeleteResult(deleteResult); Console.WriteLine("Press any key"); Console.ReadKey(); }
public void Execute() { Console.WriteLine("PLAIN SAMPLE"); var connection = new ElasticConnection("localhost", 9200); var serializer = new JsonNetSerializer(); var tweet = new Tweet { User = "******", Message = "trying out Elastic Search" }; var anotherTweet = new Tweet { User = "******", Message = "one more message" }; var tweets = new List <Tweet> { new Tweet { User = "******", Message = "first bulk tweet" }, new Tweet { User = "******", Message = "second bulk tweet" }, new Tweet { User = "******", Message = "third bulk tweet" }, }; IndexTweet(tweet, "1", connection, serializer); IndexTweet(anotherTweet, "2", connection, serializer); BulkTweetIndex(tweets, connection, serializer); CreateIndexAlias(connection, serializer); ListIndexAliases(connection, serializer); GetTweet("1", serializer, connection); SearchTweets(connection, serializer); SearchTweetsAsync(connection, serializer).Wait(); CountTweets(connection, serializer); DeleteTweeterIndex(connection, serializer); Console.WriteLine("Press any key"); Console.ReadKey(); }
public void Execute() { Console.WriteLine("CLIENT SAMPLE"); var client = new ElasticClient <Tweet>(defaultHost: "localhost", defaultPort: 9200); var firstTweet = new Tweet { User = "******", Message = "trying out Elastic Search" }; var anotherTweet = new Tweet { User = "******", Message = "one more message" }; var indexSettings = new IndexSettingsBuilder() .NumberOfShards(8) .NumberOfReplicas(1) .Analysis(analysis => analysis .Analyzer(analyzer => analyzer .Custom("keyword_lowercase", custom => custom .Tokenizer(DefaultTokenizers.keyword) .Filter(DefaultTokenFilters.lowercase)))); client.CreateIndex(new IndexCommand(index: "twitter").Refresh(), indexSettings); IndexResult indexResult1 = client.Index(new IndexCommand(index: "twitter", type: "tweet", id: "1").Refresh(), firstTweet); IndexResult indexResult2 = client.Index(Commands.Index(index: "twitter", type: "tweet", id: "2").Refresh(), anotherTweet); GetResult <Tweet> getResult = client.Get(new GetCommand(index: "twitter", type: "tweet", id: "2")); SearchResult <Tweet> searchResult = client.Search(new SearchCommand("twitter", "tweet"), new QueryBuilder <Tweet>() .Query(q => q .Term(t => t .Field(tweet => tweet.User) .Value("testUser") .Boost(2) ) )); DeleteResult deleteResult = client.Delete(Commands.Delete(index: "twitter")); PrintIndexResult(indexResult1); PrintIndexResult(indexResult2); PrintGetResult(getResult); PrintSearchResults(searchResult); PrintDeleteResult(deleteResult); Console.WriteLine("Press any key"); Console.ReadKey(); }
public void Execute() { Console.WriteLine("PLAIN SAMPLE"); var connection = new ElasticConnection("localhost", 9200); var serializer = new JsonNetSerializer(); var tweet = new Tweet { User = "******", Message = "trying out Elastic Search" }; var anotherTweet = new Tweet { User = "******", Message = "one more message" }; var tweets = new List<Tweet> { new Tweet { User = "******", Message = "first bulk tweet" }, new Tweet { User = "******", Message = "second bulk tweet" }, new Tweet { User = "******", Message = "third bulk tweet" }, }; IndexTweet(tweet, "1", connection, serializer); IndexTweet(anotherTweet, "2", connection, serializer); BulkTweetIndex(tweets, connection, serializer); CreateIndexAlias(connection, serializer); ListIndexAliases(connection, serializer); GetTweet("1", serializer, connection); SearchTweets(connection, serializer); SearchTweetsAsync(connection, serializer).Wait(); CountTweets(connection, serializer); DeleteTweeterIndex(connection, serializer); Console.WriteLine("Press any key"); Console.ReadKey(); }