Let’s setup the tools we’ll need to work with elasticsearch and run the tutorials in this book. Since elasticsearch is a standalone Java application, getting up and running is a cinch on almost any platform. You’ll want Java 1.7 or newer. You can check this by running
java -version
at a command prompt. If you don’t have Java installed on your system, download the JDK now.1.2.1 Installing Elasticsearch
Elasticsearch is a standalone Java app, and can be easily started from the command line. A copy can be obtained from the elasticsearch download pageelasticsearch download page.On Linux
If you’re running a linux distribution I recommend installing either the.deb
or .rpm
version of the software. Once installed, you can run /etc/init.d/elasticsearch start
to start the server as a daemon in the background.Mac OSX and Generic UNIX/Linux
Download the.zip
version and unzip it to a folder. Open a terminal, and navigate to the bin
directory, and run the executable elasticsearch
file within, by typing in ./elasticsearch
at the terminal.Microsoft Windows
Download the.zip
version and unpack it to a folder. Navigate to the bin
folder, then double clickelasticsearch.bat
to run.Check if your Server is Running
After you’ve started your server, you can ensure it’s running properly by opening your browser to the URL http://localhost:9200. You should see a page that looks something like Figure 1.1.
F 1.1 A Sample Response
{
"ok": true,
"status": 200,
"name": "Psyche",
"version": {
"number": "0.90.0",
"snapshot_build": false
},
"tagline": "You Know, for Search"
}
1.2.2 Loading Datasets
Some of the code samples depend on pre-built datasets being loaded into your elasticsearch server. To run those examples you’ll need a copy of the ee-datasets repository available athttps://github.com/andrewvc/ee-datasets. This repository changes frequently as the book is still in the process of being written, so be sure to check for updates frequently viagit pull
. If you’d like to obtain the datasets without using git, download the zip archive at{https://github.com/andrewvc/ee-datasets/archive/master.zip.After you’ve cloned the repository you’ll be able to load examples into your server by executing the included
elastic-loader.jar
program, providing the address of your elasticsearch server, and the path to the data-file. To load the movie_db
dataset, for example, open a command prompt in the ee-datasets
folder, and run:java -jar elastic-loader.jar http://localhost:9200 datasets/movie_db.eloader
1.2.3 Running Examples
This book makes exclusive use of elasticsearch’s most popular API, its JSON HTTP API. All examples in this book are implementation independent descriptions of HTTP requests. Feel free to use any tool you wish. While you’re free to use the client of your choice it’s recommended to use the free Elastic Hammer tool to query elasticsearch. I developed this tool specifically to aid in the teaching of this book, and its fairly simple to use. Other tools such as cURL, should work fine as well.HTTP operations in this book are described with a simple syntax consisting of the HTTP verb (
GET
, PUT
}, POST
, HEAD
, DELETE
), URL path, and request body. An example simple request can be seen in figure 1.2.
F 1.2 A Simple Request
GET /_status
F 1.3 Request with a Body
POST /_analyze?analyzer=snowball
Rollerblades
POST
request to /_analyze?analyzer=snowball
with an HTTP Body set to "rollerblades"
if executed.Examples requiring the use of a specific data-set will have that dataset’s name provided as a comment on the first line of the example. For instance:
Request with a Dataset
Before running you would need to ensure the data-set // Load Dataset: movie_db.eloader
POST /movie_db/_search?pretty=true
{"query": {"match": {"_all": "story"}}}
movie_db.eloader
was loaded into your local elasticsearch server. Please read section 1.2.2 for further information on seeding your database with .eloader
files.
0 comments:
Post a Comment