I am using ElasticSearch 8.12 App Search (Enterprise Search). The documentation for range in App Search (not query DSL) is here.
I want to give my e-commerce customers the ability to filter on a price range. After they type in a search term, there will be a filter on the right with the ability to select brand, category, etc. I would also like to include the ability to set a minimum and maximum price.
With the example provided for Date range, I assumed my value range would be something like this:
{
"query": "query",
"page": {
"size": 30,
"current": 1
},
"filters": {
"price": {
"from": 50.0,
"to": 100.0
}
}
}
However, the response is:
{
"errors": [
"Filters contains invalid value for field: price; must be a string, or an array of strings"
]
}
I'd be shocked if value range is not a valid option.
Problem
based on the error:
it seems that the problem is caused by the price field's type. actually the price field has been indexed as an string (
textorkeyword) type, so that it does not let you to apply a range query.How to check
you can simply check the
_mappingof your index to see whether the price field has been indexed as integer or not.run such a below
GETquery to get mapping of your index:How to solve the problem
while creating your index, you might have used the dynamic mapping feature implicitly, or you might used a wrong mapping for the price field.
to solve the problem, you need to recreate your index with the correct mapping values.