Quick Start
For this quick start, we are going to run Elasticsearch locally and build a small e-commerce search experience using Searchkit and instantsearch.
Running Elasticsearch
This quick start will need CORS enabled as we will be calling Elasticsearch / Opensearch directly from the browser. See Enable CORS to do this.
Alternatively, you can proxy the Elasticsearch / Opensearch requests. See Proxy Elasticsearch for more details.
Going to use Elasticsearch via Docker for this quick start.
For other options, see Setup Elasticsearch.
Below we are running Elasticsearch with CORS enabled and security disabled. For production, you should enable security and use an API key. See Setup Elasticsearch for more ways of connecting with authentication.
docker pull docker.elastic.co/elasticsearch/elasticsearch:8.6.2
docker network create elastic
docker run --name elasticsearch --net elastic -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e "xpack.security.enabled=false" -e http.cors.enabled=true -e "http.cors.allow-origin='*'" -e http.cors.allow-headers=X-Requested-With,X-Auth-Token,Content-Type,Content-Length,Authorization -e http.cors.allow-credentials=true -e network.publish_host=localhost -e xpack.security.enabled=false docker.elastic.co/elasticsearch/elasticsearch:8.6.2
Index Example E-Commerce Dataset
We are going to use the ecommerce dataset from bestbuy.
Download the sample dataset from sample-data/electronics-ecommerce/bulk.json
(opens in a new tab) and index the documents via the bulk API.
curl -H 'Content-Type: application/x-ndjson' -XPOST 'localhost:9200/_bulk?pretty' --data-binary "@bulk.json"
This will add 10000 products to the products
index.
The bulk API requires a newline delimited JSON file. The last line of the file must be a newline character.