Symfony meets Elasticsearch — Implement a search as you type feature
What do we build?
In this post we’re gonna implement a search as you type feature with Symfony. We will feed product information into Elasticsearch, build a user interface to search for a product by it’s title and manage the Symfony integration to query Elasticsearch.
What is Elasticsearch?
Elasticsearch is an open source search and analysis engine based on Apache Lucene developed in Java. Feed it with your data using a REST interface and explore it with powerful queries and aggregation possibilities. Use it as a base for analytical dashboards or realtime systems.
Elasticsearch is designed as a distributed system from the ground up to build a resilient system with replicas spread over several nodes.
You can feed data to Elasticsearch with parallel requests, because it has multiple write threads with a queue to buffer not processed requests. This allows to accelerate the data import dramatically.
As you might know from my other posts, I like Docker pretty much. So here is a simple docker-compose based setup to run Elasticsearch and Symfony in a beautiful development environment. First install Symfony in a directory like this:
docker run --rm -it -v $PWD:/app composer create-project symfony/website-skeleton symfony_elasticsearch
Now add a docker-compose.yml with the following content: