예제 #1
0
        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 data = serializer.ToJson(tweet);

            var result = connection.Put(indexCommand, data);

            // Parse index result.
            IndexResult indexResult = serializer.ToIndexResult(result);


            PrintIndexCommand(result, indexResult, indexCommand, data);
        }
예제 #2
0
        private static void CreateIndexAlias(ElasticConnection connection, JsonNetSerializer serializer)
        {
            /*
             * curl -XPUT http://localhost:9200/twitter/_alias/twitter_alias
             */
 
            string indexAliasCommand = Commands.IndexAlias("twitter", "twitter_alias")
                .Pretty();

            var result = connection.Put(indexAliasCommand);

            // Parse index result.
            var indexAliasResult = serializer.ToCommandResult(result);

            PrintIndexAliasResult(indexAliasResult, indexAliasCommand, result);
        }