{"_id":"5aba6b8cb169810058a71afb","project":"5633ebff7e9e880d00af1a53","version":{"_id":"5a8fae0268264c001f20cc00","project":"5633ebff7e9e880d00af1a53","__v":4,"createdAt":"2018-02-23T06:00:34.961Z","releaseDate":"2018-02-23T06:00:34.961Z","categories":["5a8fae0268264c001f20cc01","5a8fae0268264c001f20cc02","5a8fae0368264c001f20cc03","5a8fae0368264c001f20cc04","5a8fae0368264c001f20cc05","5a8fae0368264c001f20cc06","5a8fae0368264c001f20cc07","5a8fae0368264c001f20cc08","5a8fae0368264c001f20cc09","5abaa7eb72d6dc0028a07bf3","5b8ee7842790f8000333f9ba","5b8ee8f244a21a00034b5cd9"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"2.0.0","version":"2.0"},"category":{"_id":"5a8fae0268264c001f20cc02","version":"5a8fae0268264c001f20cc00","project":"5633ebff7e9e880d00af1a53","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-12-23T20:06:16.013Z","from_sync":false,"order":4,"slug":"quickstart-guides-1","title":"Quickstart Guides"},"user":"5ab13dd42459e0004e761001","githubsync":"","__v":0,"parentDoc":null,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2018-03-27T16:04:28.826Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"settings":"","results":{"codes":[]},"auth":"required","params":[],"url":""},"isReference":false,"order":10,"body":"Bonsai Elasticsearch integrates with your .Net app quickly and easily, whether you're running on Heroku or self hosting. \n\nFirst, make sure to add the Elasticsearch.Net and NEST client to your dependencies list:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"...\\n<PackageReference Include=\\\"Elasticsearch.Net\\\" Version=\\\"6.0.2\\\" />\\n<PackageReference Include=\\\"NEST\\\" Version=\\\"6.0.2\\\" />\\n....\",\n      \"language\": \"xml\",\n      \"name\": \"Project.csproj\"\n    }\n  ]\n}\n[/block]\nYou'll also want to make sure the client is installed locally for testing purposes:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$ dotnet restore\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\n*Self-hosted users:* when you sign up with Bonsai and create a cluster, it will be provisioned with a custom URL that looks like https://user:pass:::at:::my-awesome-cluster.us-east-1.bonsai.io. Make note of this URL because it will be needed momentarily.\n\n*Heroku users:* you'll want to make sure that you've added Bonsai Elasticsearch to your app. Visit our addons page to see available plans. You can add Bonsai to your app through the dashboard, or by running:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$ heroku addons:create bonsai:<plan_slug> -a <app_name>\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nUpdate your Main.cs file with the following:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"using System;\\nusing Nest;\\n\\nnamespace search.con\\n{\\n    class Program\\n    {\\n        static void Main(string[] args)\\n        {\\n            var server = new Uri(Environment.GetEnvironmentVariable(\\\"BONSAI_URL\\\"));\\n            var conn = new ConnectionSettings(server);\\n            var client = new ElasticClient(conn);\\n\\n            var resp = client.Ping();\\n            if (resp.IsValid)\\n            {\\n                Console.WriteLine(\\\"All is well\\\");\\n            }\\n            else\\n            {\\n                Console.WriteLine(\\\"Elasticsearch cluster is down\\\");\\n            }\\n        }\\n    }\\n}\",\n      \"language\": \"csharp\",\n      \"name\": \"Main.cs\"\n    }\n  ]\n}\n[/block]\nThe code above does several things:\n\n1. Pulls your Bonsai URL from the environment (you never want to hard-code this value -- it's a bad practice)\n2. References the Elasticsearch.Net and NEST libraries\n3. Instantiates the client using your private Bonsai URL\n4. Pings the cluster to test the connection\n\n*Self-hosted users:* You will need to take an additional step and add your Bonsai URL to your server/dev environment variables. Something like this should work:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$ export BONSAI_URL=\\\"https://username:password@my-awesome-cluster-123.us-east-1.bonsai.io\\\"\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\n*Heroku users:* You don't need to worry about this step. The environment variable is automatically populated for you when you add Bonsai Elasticsearch to your app. You can verify that it exists by running:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"$ heroku config:get BONSAI_URL\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nGo ahead and spin up your .Net app with `dotnet run`. Heroku users can also push the changes to Heroku, and monitor the logs with `heroku logs --tail`. Either way, you should see something like this:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"    Elasticsearch INFO: 2016-02-03T23:44:41Z\\n      Adding connection to https://nodejs-test-012345.us-east-1.bonsai.io/\\n    \\n    Elasticsearch DEBUG: 2016-02-03T23:44:41Z\\n      Request complete\\n    \\n    Elasticsearch TRACE: 2016-02-03T23:44:41Z\\n      -> HEAD https://nodejs-test-012345.us-east-1.bonsai.io:443/?hello=elasticsearch\\n      \\n      <- 200\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\nThe above output indicates that the client was successfully initiated and was able to contact the cluster.\n\n*Questions? Problems?*\nFeel free to [ping our support](mailto:support@bonsai.io) if something isn't working right and we'll do what we can to help out.","excerpt":"","slug":"net2","type":"basic","title":".Net"}
Bonsai Elasticsearch integrates with your .Net app quickly and easily, whether you're running on Heroku or self hosting. First, make sure to add the Elasticsearch.Net and NEST client to your dependencies list: [block:code] { "codes": [ { "code": "...\n<PackageReference Include=\"Elasticsearch.Net\" Version=\"6.0.2\" />\n<PackageReference Include=\"NEST\" Version=\"6.0.2\" />\n....", "language": "xml", "name": "Project.csproj" } ] } [/block] You'll also want to make sure the client is installed locally for testing purposes: [block:code] { "codes": [ { "code": "$ dotnet restore", "language": "shell" } ] } [/block] *Self-hosted users:* when you sign up with Bonsai and create a cluster, it will be provisioned with a custom URL that looks like https://user:pass@my-awesome-cluster.us-east-1.bonsai.io. Make note of this URL because it will be needed momentarily. *Heroku users:* you'll want to make sure that you've added Bonsai Elasticsearch to your app. Visit our addons page to see available plans. You can add Bonsai to your app through the dashboard, or by running: [block:code] { "codes": [ { "code": "$ heroku addons:create bonsai:<plan_slug> -a <app_name>", "language": "shell" } ] } [/block] Update your Main.cs file with the following: [block:code] { "codes": [ { "code": "using System;\nusing Nest;\n\nnamespace search.con\n{\n class Program\n {\n static void Main(string[] args)\n {\n var server = new Uri(Environment.GetEnvironmentVariable(\"BONSAI_URL\"));\n var conn = new ConnectionSettings(server);\n var client = new ElasticClient(conn);\n\n var resp = client.Ping();\n if (resp.IsValid)\n {\n Console.WriteLine(\"All is well\");\n }\n else\n {\n Console.WriteLine(\"Elasticsearch cluster is down\");\n }\n }\n }\n}", "language": "csharp", "name": "Main.cs" } ] } [/block] The code above does several things: 1. Pulls your Bonsai URL from the environment (you never want to hard-code this value -- it's a bad practice) 2. References the Elasticsearch.Net and NEST libraries 3. Instantiates the client using your private Bonsai URL 4. Pings the cluster to test the connection *Self-hosted users:* You will need to take an additional step and add your Bonsai URL to your server/dev environment variables. Something like this should work: [block:code] { "codes": [ { "code": "$ export BONSAI_URL=\"https://username:password@my-awesome-cluster-123.us-east-1.bonsai.io\"", "language": "shell" } ] } [/block] *Heroku users:* You don't need to worry about this step. The environment variable is automatically populated for you when you add Bonsai Elasticsearch to your app. You can verify that it exists by running: [block:code] { "codes": [ { "code": "$ heroku config:get BONSAI_URL", "language": "shell" } ] } [/block] Go ahead and spin up your .Net app with `dotnet run`. Heroku users can also push the changes to Heroku, and monitor the logs with `heroku logs --tail`. Either way, you should see something like this: [block:code] { "codes": [ { "code": " Elasticsearch INFO: 2016-02-03T23:44:41Z\n Adding connection to https://nodejs-test-012345.us-east-1.bonsai.io/\n \n Elasticsearch DEBUG: 2016-02-03T23:44:41Z\n Request complete\n \n Elasticsearch TRACE: 2016-02-03T23:44:41Z\n -> HEAD https://nodejs-test-012345.us-east-1.bonsai.io:443/?hello=elasticsearch\n \n <- 200", "language": "shell" } ] } [/block] The above output indicates that the client was successfully initiated and was able to contact the cluster. *Questions? Problems?* Feel free to [ping our support](mailto:support@bonsai.io) if something isn't working right and we'll do what we can to help out.