A simple project using Elasticsearch and GraphQL.
run make
or docker-compose up
run docker ps
or docker-compose top
http://localhost:9200/
POST localhost:9200/sample/product/sku-1
{
"name" : "FirstProduct",
"price" : 100,
"categories" : "category-1",
"status" : "on sale"
}
POST localhost:9200/sample/product/sku-1/_update
{
"doc":{
"price" : 101
}
}
Delete one single document
DELETE localhost:9200/sample/product/sku-1
Delete all documents from an index
DELETE localhost:9200/sample
GET localhost:9200/sample/product/sku-1
products-sample.json
{"index":{"_index":"sample","_type":"product","_id":"sku-1"}}
{"name": "FirstProduct", "price": 100, "categories": ["category-1", "status": "instock"}
Run command:
curl -XPOST 'localhost:9200/sample/_bulk?pretty' --data-binary @products-sample.json
Simple query:
GET localhost:9200/_search?q=FirstProduct
GET localhost:9200/sample/_search?q=FirstProduct
GET localhost:9200/sample/product/_search?q=FirstProduct
Query by fields:
GET localhost:9200/sample/product/_search?q=categories:(category-1|category-2) status:instock
POST localhost:9200/sample/product/_search
{
"query":{
"bool": {
"must" : [
{
"match" : {
"categories" : "category-1"
}
},
{
"match" : {
"status" : "instock"
}
},
{
"match" : {
"price" : 200
}
}
]
}
}
}
POST localhost:9200/sample/product/_search
{
"size":0,
"aggs" : {
"Popular categories" : {
"terms" : {
"field" : "category.keyword"
}
}
}
}