{"_id":"5851a2bffa1fd92300ab54b1","parentDoc":null,"project":"5633ebff7e9e880d00af1a53","user":"5637d336aa96490d00a64f81","version":{"_id":"5633ec007e9e880d00af1a56","project":"5633ebff7e9e880d00af1a53","__v":15,"createdAt":"2015-10-30T22:15:28.105Z","releaseDate":"2015-10-30T22:15:28.105Z","categories":["5633ec007e9e880d00af1a57","5633f072737ea01700ea329d","5637a37d0704070d00f06cf4","5637cf4e7ca5de0d00286aeb","564503082c74cf1900da48b4","564503cb7f1fff210078e70a","567af26cb56bac0d0019d87d","567afeb8802b2b17005ddea0","567aff47802b2b17005ddea1","567b0005802b2b17005ddea3","568adfffcbd4ca0d00aebf7e","56ba80078cf7c9210009673e","574d127f6f075519007da3d0","574fde60aef76a0e00840927","57a22ba6cd51b22d00f623a0"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"__v":0,"category":{"_id":"567afeb8802b2b17005ddea0","project":"5633ebff7e9e880d00af1a53","pages":["56b3cd7ac25dea2b00b0caf6"],"version":"5633ec007e9e880d00af1a56","__v":1,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-12-23T20:06:16.013Z","from_sync":false,"order":2,"slug":"quickstart-guides-1","title":"Quickstart Guides"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-12-14T19:51:27.663Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"settings":"","results":{"codes":[]},"auth":"required","params":[],"url":""},"isReference":false,"order":6,"body":"Searchkick is an alternative to the official Elasticsearch Rails client. It provides some out of the box support for features that the official client does not (autocomplete, spelling suggestions, stemming, etc).\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"Note\",\n  \"body\": \"This documentation covers the basics of using the Searchkick client for Elasticsearch and is not meant to be exhaustive. For complete documentation, please see the project's GitHub page: https://github.com/ankane/searchkick. \\n\\nUsers who are using the official Elasticsearch Rails client should read the documentation here: https://docs.bonsai.io/docs/ruby-on-rails\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Getting started\"\n}\n[/block]\nSearchkick looks for an environment variable called `ELASTICSEARCH_URL` to determine how to connect to your Elasticsearch cluster. If this variable is not found, Searchkick will default to `http://localhost:9200`. The first step is to make sure that this environment variable is present so Searchkick can communicate with Elasticsearch.\n\n**Heroku users:**\nWhen Bonsai is added to your application, it automatically creates an environment variable called `BONSAI_URL` and populates it with your cluster URL. You can initialize the `ELASTICSEARCH_URL` variable by running the following in a terminal:\n\n```\nheroku config:set ELASTICSEARCH_URL=`heroku config:get BONSAI_URL`\n```\n\n**Direct users**\nUsers who sign up for Bonsai through our website will need to create the environment variable manually. For Linux/BSD/OSX, this will probably look something like the following:\n\n```\nexport ELASTICSEARCH_URL=\"<URL copy/pasted from your Bonsai dashboard>\"\n```\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Setting up Rails\"\n}\n[/block]\nAdd the searchkick gem to your Gemfile\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"gem 'searchkick'\",\n      \"language\": \"ruby\"\n    }\n  ]\n}\n[/block]\nMake sure to run `bundle install` after modifying your Gemfile. Next, add searchkick to the models you want to search, like so:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"class Product < ActiveRecord::Base\\n  searchkick\\nend\",\n      \"language\": \"ruby\"\n    }\n  ]\n}\n[/block]\nYou should now be able to create an index on your cluster and populate it with your data by running `Product.reindex` within a Rails console. Once your data is indexed, you can search it from a console as well:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"products = Product.search \\\"apples\\\"\\nproducts.each do |product|\\n  puts product.name\\nend\",\n      \"language\": \"ruby\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Next steps\"\n}\n[/block]\nOnce you have confirmed that your application is able to communicate with your Bonsai cluster, you can begin the work of configuring your other models and search options. Please consult the Searchkick documentation for more details: https://github.com/ankane/searchkick\n\nIf you have any issues, please don't hesitate to open a support ticket by emailing [support:::at:::bonsai.io](mailto:support@bonsai.io).","excerpt":"","slug":"searchkick","type":"basic","title":"Searchkick"}
Searchkick is an alternative to the official Elasticsearch Rails client. It provides some out of the box support for features that the official client does not (autocomplete, spelling suggestions, stemming, etc). [block:callout] { "type": "warning", "title": "Note", "body": "This documentation covers the basics of using the Searchkick client for Elasticsearch and is not meant to be exhaustive. For complete documentation, please see the project's GitHub page: https://github.com/ankane/searchkick. \n\nUsers who are using the official Elasticsearch Rails client should read the documentation here: https://docs.bonsai.io/docs/ruby-on-rails" } [/block] [block:api-header] { "type": "basic", "title": "Getting started" } [/block] Searchkick looks for an environment variable called `ELASTICSEARCH_URL` to determine how to connect to your Elasticsearch cluster. If this variable is not found, Searchkick will default to `http://localhost:9200`. The first step is to make sure that this environment variable is present so Searchkick can communicate with Elasticsearch. **Heroku users:** When Bonsai is added to your application, it automatically creates an environment variable called `BONSAI_URL` and populates it with your cluster URL. You can initialize the `ELASTICSEARCH_URL` variable by running the following in a terminal: ``` heroku config:set ELASTICSEARCH_URL=`heroku config:get BONSAI_URL` ``` **Direct users** Users who sign up for Bonsai through our website will need to create the environment variable manually. For Linux/BSD/OSX, this will probably look something like the following: ``` export ELASTICSEARCH_URL="<URL copy/pasted from your Bonsai dashboard>" ``` [block:api-header] { "type": "basic", "title": "Setting up Rails" } [/block] Add the searchkick gem to your Gemfile [block:code] { "codes": [ { "code": "gem 'searchkick'", "language": "ruby" } ] } [/block] Make sure to run `bundle install` after modifying your Gemfile. Next, add searchkick to the models you want to search, like so: [block:code] { "codes": [ { "code": "class Product < ActiveRecord::Base\n searchkick\nend", "language": "ruby" } ] } [/block] You should now be able to create an index on your cluster and populate it with your data by running `Product.reindex` within a Rails console. Once your data is indexed, you can search it from a console as well: [block:code] { "codes": [ { "code": "products = Product.search \"apples\"\nproducts.each do |product|\n puts product.name\nend", "language": "ruby" } ] } [/block] [block:api-header] { "type": "basic", "title": "Next steps" } [/block] Once you have confirmed that your application is able to communicate with your Bonsai cluster, you can begin the work of configuring your other models and search options. Please consult the Searchkick documentation for more details: https://github.com/ankane/searchkick If you have any issues, please don't hesitate to open a support ticket by emailing [support@bonsai.io](mailto:support@bonsai.io).