# NOT RUN {
if (!index_exists("iris")) {
invisible(docs_bulk(iris, "iris"))
}
body1 <- '{
"inline" : {
"query": { "match" : { "{{my_field}}" : "{{my_value}}" } },
"size" : "{{my_size}}"
},
"params" : {
"my_field" : "Species",
"my_value" : "setosa",
"my_size" : 3
}
}'
Search_template(body = body1)
body2 <- '{
"inline": {
"query": {
"match": {
"Species": "{{query_string}}"
}
}
},
"params": {
"query_string": "versicolor"
}
}'
Search_template(body = body2)
# pass in a list
mylist <- list(
inline = list(query = list(match = list(`{{my_field}}` = "{{my_value}}"))),
params = list(my_field = "Species", my_value = "setosa", my_size = 3L)
)
Search_template(body = mylist)
## Validating templates w/ Search_template_render()
Search_template_render(body = body1)
Search_template_render(body = body2)
## pre-registered templates
### register a template
body3 <- '{
"template": {
"query": {
"match": {
"Species": "{{query_string}}"
}
}
}
}'
Search_template_register('foobar', body = body3)
### get template
Search_template_get('foobar')
### use the template
body4 <- '{
"id": "foobar",
"params": {
"query_string": "setosa"
}
}'
Search_template(body = body4)
### delete the template
Search_template_delete('foobar')
# }
Run the code above in your browser using DataLab