An open API service indexing awesome lists of open source software.

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.

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
}
}
}
}
```