Skip to content

Instantly share code, notes, and snippets.

@purintai
Last active November 10, 2016 11:29
Show Gist options
  • Select an option

  • Save purintai/aa57c8e309433a2c40e7a246b926e27a to your computer and use it in GitHub Desktop.

Select an option

Save purintai/aa57c8e309433a2c40e7a246b926e27a to your computer and use it in GitHub Desktop.
Elasticsearch inline script よくわからない
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
}
}
}
}
}
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