Last active
November 10, 2016 11:29
-
-
Save purintai/aa57c8e309433a2c40e7a246b926e27a to your computer and use it in GitHub Desktop.
Elasticsearch inline script よくわからない
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| GET /products/_search | |
| { | |
| "query": { | |
| "bool": { | |
| "must": { | |
| "script": { | |
| "script": { | |
| "lang": "painless", | |
| "inline": "doc['sale_price'].value > 0 && doc['sale_begin_at'].value <= params.t && doc['sale_end_at'].value > params.t", | |
| "params": { | |
| "t": 1478776232086 | |
| } | |
| } | |
| } | |
| } | |
| } | |
| }, | |
| "_source": true, | |
| "script_fields": { | |
| "current_price": { | |
| "script": { | |
| "lang": "painless", | |
| "inline": "if (doc['sale_price'].value > 0 && doc['sale_begin_at'].value <= params.t && doc['sale_end_at'].value > params.t) { doc['sale_price'] } else { doc['price'] }", | |
| "params": { | |
| "t": 1478776232086 | |
| } | |
| } | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| GET /products/_search | |
| { | |
| "query": { | |
| "match_all": {} | |
| }, | |
| "_source": true, | |
| "script_fields": { | |
| "current_price": { | |
| "script": { | |
| "lang": "painless", | |
| "inline": "if (doc['sale_price'].value > 0 && doc['sale_begin_at'].value <= params.t && doc['sale_end_at'].value > params.t) { doc['sale_price'] } else { doc['price'] }", | |
| "params": { | |
| "t": 1478776232086 | |
| } | |
| } | |
| }, | |
| "on_sale?": { | |
| "script": { | |
| "lang": "painless", | |
| "inline": "doc['sale_price'].value > 0 && doc['sale_begin_at'].value <= params.t && doc['sale_end_at'].value > params.t", | |
| "params": { | |
| "t": 1478776232086 | |
| } | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment