Website Search Box 101

I would like to create a search box for one of my websites, similar to the search box on Wikipedia's pages. I work with PHP and MySQL on a Mac.

I watched about half of the ElasticSearch introductory webinar, but it's way over my head. I'm not even familiar with the functions they were talking about (e.g. searching for books).

Anyway, I wondered how many hoops would I have to jump through to make a simple web page search box? Is there a simple tutorial for that specific function that anyone can point me to?

Thank you.

Hi David,

welcome to the Elasticsearch world. :slight_smile:

I think the most basic thing is how to get content into Elasticsearch (which is called indexing) and how to search using the query string query. There are lots of other topics but once you've mastered these two, you can go on with more complex things like bulk indexing, the query DSL, mappings or analysis.

To get started I suggest you just download Elasticsearch, start it and install the "Sense" extension in your browser (if you use Chrome). With Sense it is more convenient to enter commands. And it is the easiest way to learn Elasticsearch.

To get content into Elasticsearch, you need to add so-called "documents". You can copy and paste the commands below directly into the Sense console (note that is very simplified but you can learn the details on the go):

# insert a document into Elasticsearch
PUT /company/employee/1
    "name": "Max Smith"

PUT /company/employee/2
    "name": "Clara Smith"

# Find the documents again by a search
GET /company/employee/_search?q=Smith

#Find a specific document by its id
GET /company/employee/2

In this example company is your so-called, index. It is where your data live. Within this index you can have multiple types. Here we have just one: employee. A type in Elasticsearch is similar (but not identical) to a struct in C. And finally, each document has an id. You can either provide one to Elasticsearch or have Elasticsearch generate one for you.

These are the very basics: You are now able to get data in and out of Elasticsearch. To understand more details, I suggest the Getting Started section of the Definitive guide.

For PHP, there is also an official language client, so you don't have to create the HTTP requests using a low-level HTTP library.