Hi,
I have a rather complex use case for App Search with engines based on Elasticsearch indexes. I managed to build ES indexes and AP engines that match almost all of my criteria but I stumble on one of the last things I'd like to setup.
I have products and these products can have promotions, only applicable between two dates. I'd like to add fields to my indexes to be able to easily know if a product is currently promoted and prioritize those who are.
As I don't want to rebuild products index every day, I imagined a solution with a promoted_on
mapping field (of type date), to store dates when a product (document) is promoted and a promoted
runtime field (of type long as boolean does not seem to be supported), that emits 0 or 1 depending if today appears in doc['promoted_on']
.
My questions are:
What is the best match in App Search supported field types for a boolean?
I used byte
for some other fields in my indexes and the closest field type supported on a runtime field seem to be long
but is this the best way to do?
According to documentation, number fields are the only one that can be used in all of boosts, facets and filters App Search APIs but this post suggest to use keywords.
Is it possible to use a runtime field declared on an ES index in an App Search query?
I'd also like to have the runtime field value returned for every documents in an App Search response.
What should be the script of my promoted
runtime field?
I tried this:
{
"runtime": {
"promoted": {
"type": "long",
"script": {
"source": "emit(doc['promoted_on'].contains(LocalDate.now()) ? 1 : 0);"
}
}
}
}
But I don't think it will work. It seems there is a lot of different ways (libraries) to manipulate dates (without time nor timezone) in Java but no simple one and different sources between painless documentation, this forum or SO do not even agree on of what type are exactly values in a script.