elasticizer: renamed size parameter to batch_size, created max_batch parameter to limit the number of results returned
query_string: renamed x parameter to query, added fields parameter to select what fields to return and random boolean parameter to define whether the returned results should be randomizedmaster
parent
d0e9bf565b
commit
4f8b1f2024
@ -1,26 +1,62 @@
|
||||
#' Generate a query string query for ElasticSearch
|
||||
#'
|
||||
#' Generate a query string query for ElasticSearch
|
||||
#' @param x Query string in ElasticSearch query string format
|
||||
#' @param query Query string in ElasticSearch query string format
|
||||
#' @param fields List of field names to return, defaults to all
|
||||
#' @param random Return randomized results. Boolean, defaults to FALSE
|
||||
#' @return A formatted ElasticSearch query string query
|
||||
#' @export
|
||||
#' @examples
|
||||
#' query_string(x)
|
||||
#' query_string(query)
|
||||
#################################################################################################
|
||||
#################################### Get data from ElasticSearch ################################
|
||||
#################################################################################################
|
||||
|
||||
query_string <- function(x) {
|
||||
query_string <- function(query, fields = F, random = F) {
|
||||
if (fields == F) {
|
||||
fields <- '*'
|
||||
}
|
||||
if (random == T) {
|
||||
return(paste0(
|
||||
'{
|
||||
"_source": ',toJSON(fields),',
|
||||
"query": {
|
||||
"function_score": {
|
||||
"query": {
|
||||
"bool":{
|
||||
"filter": [{
|
||||
"query_string" : {
|
||||
"default_field" : "text",
|
||||
"query" : "',query,'",
|
||||
"default_operator": "AND",
|
||||
"allow_leading_wildcard" : false
|
||||
}
|
||||
}]
|
||||
}
|
||||
},
|
||||
"random_score": {},
|
||||
"boost_mode": "sum"
|
||||
}
|
||||
}
|
||||
}'
|
||||
))
|
||||
} else {
|
||||
return(paste0(
|
||||
'{
|
||||
"_source": ',toJSON(fields),',
|
||||
"query": {
|
||||
"bool":{
|
||||
"filter": [{
|
||||
"query_string" : {
|
||||
"default_field" : "text",
|
||||
"query" : "',x,'",
|
||||
"query" : "',query,'",
|
||||
"default_operator": "AND",
|
||||
"allow_leading_wildcard" : false
|
||||
}
|
||||
}]
|
||||
}
|
||||
}'
|
||||
}
|
||||
}'
|
||||
))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in new issue