https://github.com/crystallizeapi/crystallize-elasticsearch-example-js
An example service integrating ElasticSearch with Crystallize.
https://github.com/crystallizeapi/crystallize-elasticsearch-example-js
Last synced: 3 months ago
JSON representation
An example service integrating ElasticSearch with Crystallize.
- Host: GitHub
- URL: https://github.com/crystallizeapi/crystallize-elasticsearch-example-js
- Owner: CrystallizeAPI
- License: mit
- Created: 2020-04-07T09:20:50.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2022-12-12T10:06:04.000Z (over 2 years ago)
- Last Synced: 2025-01-20T17:24:14.311Z (5 months ago)
- Language: JavaScript
- Size: 531 KB
- Stars: 0
- Watchers: 7
- Forks: 2
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Crystallize ElasticSearch Example (JS)
> An example service for integrating ElasticSearch with Crystallize.
## Getting Started
### Creating an ElasticSearch Instance
#### Locally
For local development you can set up an ElasticSearch cluster easily via
docker-compose.```sh
docker-compose up -d
```This will provide you with an ElasticSearch node available at
`http://localhost:9200`.Create a file named `.env` in the root of this project and place the following
variable in order to use your local cluster for indexing and searching.```
ES_NODE=http://localhost:9200
```#### Elastic Cloud
You can also create a deployment on [Elastic Cloud](https://www.elastic.co). If
you are using Elastic Cloud, create a new deployment and add the node, username,
and password to your `.env` file in the root of this project in order to use it
for indexing and searching. The username and password are generated after your
service has been deployed.```
ES_NODE=
ES_USER=
ES_PASS=
```### Running the Server
Being an example, this project exposes both queries for searching as well as
mutations for indexing a tenant via GraphQL. You may wish to remove mutations
from a publicly exposed endpoint.You can run the server with either `yarn start` for production, or `yarn dev`
for local development.This will provide you with a playground available at
`http://localhost:4000/graphql`.#### Indexing Your Tenant
You can index your tenant's catalogue by running the `bulkIndex` mutation via
GraphQL. As an example you can try indexing the `teddy-bear-shop`, or
alternatively your own tenant.```graphql
mutation {
bulkIndex(tenant: "teddy-bear-shop", language: "en") {
success
message
executionTime
}
}
```#### Searching Your Catalogue
You can search your catalogue using the `productVariants` query. You can view
the full schema via the GraphQL playground with all the fields you can query,
search and filter. For example:```graphql
query {
productVariants(
filter: { searchTerm: "kiwi" }
orderBy: { field: PRICE, direction: DESC }
) {
totalCount
productVariants {
variant {
name
price
stock
}
product {
name
}
}
}
}
```