Sorting for price with special offers


(chris_kal) #1

Hi,

we use an index with products that have a default price. For certain
periods of time a product can have a special price.

The mapping looks like this at the moment:

"mappings" : {
    "products" : {
        "properties" : {
            "defaultPrice" : { "type" : "float" },
            "actionPrice" : {
                "type" : "nested",
                "properties" : {
                    "begin" : { "type" : "date", "format" : 

"YYYY-MM-dd" },
"end" : { "type" : "date", "format" : "YYYY-MM-dd"
},
"price" : { "type" : "float" }
}
}, ...

The user can sort for the price. So in the query we need the logic that if
the current time is between a begin and end, then take this price else take
the defaultPrice. Is that possible? How can I do that?

Thanks

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/8fc717a4-3a3d-4a60-b83b-67f417b47d8d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(Florentin Zorca) #2

Hi,

I have never tried it, so take my advice with a grain of salt.
Your problem looks like a good usage of function scoring:

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#_using_function_score

Functions used in scoring can have filters. So theoretically you should
obtain what you want a first function with a date range filter and the
value of the time limited price and a second function, without filters
which has the value of the default price. You should probably use
"score_mode": "first" and "boos_mode": "replace" so that you only sort by
these functions.

I hope this idea helps a little.

Kind regards,
Florentin

Am Dienstag, 27. Mai 2014 13:46:52 UTC+2 schrieb Christof Kaleschke:

Hi,

we use an index with products that have a default price. For certain
periods of time a product can have a special price.

The mapping looks like this at the moment:

"mappings" : {
    "products" : {
        "properties" : {
            "defaultPrice" : { "type" : "float" },
            "actionPrice" : {
                "type" : "nested",
                "properties" : {
                    "begin" : { "type" : "date", "format" : 

"YYYY-MM-dd" },
"end" : { "type" : "date", "format" : "YYYY-MM-dd"
},
"price" : { "type" : "float" }
}
}, ...

The user can sort for the price. So in the query we need the logic that if
the current time is between a begin and end, then take this price else take
the defaultPrice. Is that possible? How can I do that?

Thanks

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/219804cb-6cdb-41cc-bbb8-ddd61eda4076%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(Florentin Zorca) #3

Hi Christof,

Another Idea, more like a brute force approach: keep a "current_price"
field and update it daily with a cron job, either with the default price or
with the promotional price. This way you only need to change a very little
in your queries (sort by the new field) and just add a job to "fix the
prices" daily.

This should be simpler solution than changing your queries to
function_score.

Florentin

Am Dienstag, 27. Mai 2014 13:46:52 UTC+2 schrieb Christof Kaleschke:

Hi,

we use an index with products that have a default price. For certain
periods of time a product can have a special price.

The mapping looks like this at the moment:

"mappings" : {
    "products" : {
        "properties" : {
            "defaultPrice" : { "type" : "float" },
            "actionPrice" : {
                "type" : "nested",
                "properties" : {
                    "begin" : { "type" : "date", "format" : 

"YYYY-MM-dd" },
"end" : { "type" : "date", "format" : "YYYY-MM-dd"
},
"price" : { "type" : "float" }
}
}, ...

The user can sort for the price. So in the query we need the logic that if
the current time is between a begin and end, then take this price else take
the defaultPrice. Is that possible? How can I do that?

Thanks

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/9dc4d381-151e-46f6-9f96-1372dee92e42%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(system) #4