Searches

Creates a search

With this endpoint you can write any with Elaticsearch 5.1 compatible query inside the search parameter. Read the Elasticsearch documentation.

Example payload to filter by properties and categories

{
  "search": {
    "from": 0,
    "query": {
      "bool": {
        "filter": [
          {
            "terms": {
              "properties.id": [59642]
            }
          },
          {
            "terms": {
              "categories.id": [77199]
            }
          },
          {
            "term": {
              "enabled": true
            }
          }
        ],
        "must": []
      }
    },
    "size": 24,
    "sort": "_score"
  }
}

Example payload to aggregate properties and categories

{
  "search": {
    "aggs": {
      "maxPrice": {
        "max": {
          "field": "realprice"
        }
      },
      "minPrice": {
        "min": {
          "field": "realprice"
        }
      },
      "categories.id": {
        "terms": {
          "field": "categories.id",
          "size": 1000
        }
      },
      "properties.id": {
        "terms": {
          "field": "properties.id",
          "size": 1000
        }
      }
    },
    "query": {
      "bool": {
        "filter": [
          {
            "terms": {
              "categories.id": [
                77199
              ]
            }
          }          
        ],
        "must": []
      }
    },
    "size": 0
  }
}

Endpoint

POST /v1/searches

Parameters

Name Description
search required Search query

Request

curl "https://capi.storyblok.com/v1/searches" -d '{"search":{"aggs":{"minPrice":{"min":{"field":"price"}}},"query":{"bool":{"must":{"multi_match":{"query":"Tshirt","fields":["name^4"],"type":"phrase_prefix"}},"filter":[]}}}}' -X POST \
	-H "Accept: application/json" \
	-H "Content-Type: application/json"
	-H "Authorization: Token token=dde9c5d0b2b85ee0469cb90a05626aff" \

Response

{
  "products": [
    {
      "id": 40411,
      "sku": "1530723433.114839",
      "ean": "",
      "name": "Tshirt",
      "slug": "divina",
      "description": null,
      "description_md": null,
      "excerpt": null,
      "price": 10.5,
      "saleprice": 0.0,
      "realprice": 10.5,
      "free_shipping": false,
      "shippable": true,
      "taxable": true,
      "fixed_quantity": false,
      "weight": "0",
      "track_stock": false,
      "quantity": 0,
      "related_products": null,
      "images": [

      ],
      "seo_title": null,
      "meta": null,
      "enabled": true,
      "video": "",
      "height": 0.0,
      "width": 0.0,
      "depth": 0.0,
      "factory_price": 0.0,
      "video_img": "",
      "installments": 0,
      "stared": false,
      "seo_description": "",
      "seo_keywords": "",
      "variant_details": false,
      "subscription_days": 0,
      "subscription_period": "",
      "subscription_trial": null,
      "lookable": false,
      "purchasable": true,
      "reduction_type": "",
      "reduction_amount": 0.0,
      "parent_id": 0,
      "production_time": 0,
      "display_size_as": "",
      "child_image": null,
      "category_ids": [

      ],
      "property_ids": [

      ],
      "primary_image": "",
      "rating_value": 0,
      "review_count": 0,
      "product_option_ids": [

      ],
      "product_type": "standard",
      "sales": 0,
      "updated_at": "2018-07-04T16:57:13.000Z",
      "created_at": "2018-07-04T16:57:13.000Z",
      "currency": "USD"
    }
  ],
  "total": 1,
  "aggregations": {
    "minPrice": {
      "value": 10.5
    }
  },
  "suggestions": {
  }
}