vue-storefront-api
vue-storefront-api copied to clipboard
Configurable limits over ElasticSearch results
I think it would be great to add some kind of configurable request limits for over-fetching Elastic data. I mean we can pretty easily configure the maximum size of the offset/limit parameters for the Elastic here in the catalog.js
The filter should work with storefront-query-builder queries and ElasticSearch DSL. In both cases it's just a JSON.
If there is a search-query format selected then the query format is like this:
{
"_availableFilters": [
{
"field": "color",
"scope": "catalog",
"options": {}
},
{
"field": "erin_recommends",
"scope": "catalog",
"options": {}
},
{
"field": "price",
"scope": "catalog",
"options": {}
},
{
"field": "size",
"scope": "catalog",
"options": {}
}
],
"_appliedFilters": [
{
"attribute": "visibility",
"value": {
"in": [
2,
3,
4
]
},
"scope": "default"
},
{
"attribute": "status",
"value": {
"in": [
0,
1
]
},
"scope": "default"
},
{
"attribute": "category_ids",
"value": {
"in": [
20,
21,
23,
24,
25,
26,
22,
27,
28
]
},
"scope": "default"
}
],
"_appliedSort": [
{
"field": "updated_at",
"options": "desc"
}
],
"_searchText": ""
}
in that case the GET parameters from and size are in charge of pagination
In other cases the ElasticSearch DSL :
{
"query": {
"bool": {
"filter": {
"bool": {
"must": [
{
"terms": {
"visibility": [
2,
3,
4
]
}
},
{
"terms": {
"status": [
0,
1
]
}
},
{
"terms": {
"category_ids": [
20,
21,
23,
24,
25,
26,
22,
27,
28
]
}
}
]
}
}
}
},
"aggs": {
"agg_terms_color": {
"terms": {
"field": "color",
"size": 10
}
},
"agg_terms_color_options": {
"terms": {
"field": "color_options",
"size": 10
}
},
"agg_terms_erin_recommends": {
"terms": {
"field": "erin_recommends",
"size": 10
}
},
"agg_terms_erin_recommends_options": {
"terms": {
"field": "erin_recommends_options",
"size": 10
}
},
"agg_terms_price": {
"terms": {
"field": "price"
}
},
"agg_range_price": {
"range": {
"field": "price",
"ranges": [
{
"from": 0,
"to": 50
},
{
"from": 50,
"to": 100
},
{
"from": 100,
"to": 150
},
{
"from": 150
}
]
}
},
"agg_terms_size": {
"terms": {
"field": "size",
"size": 10
}
},
"agg_terms_size_options": {
"terms": {
"field": "size_options",
"size": 10
}
}
}
}
in that case the GET parameters from and size are in charge of pagination
The page size limit should be possible to set via config variables. You might want to think on limiting the other features as well (eg. the number of aggregation fields, match_all, number of queries in time per user (aka. throttling)