Skip to content

Commit

Permalink
track_total_hits in request for elastic 7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
orenov authored and sckott committed Jul 25, 2019
1 parent 0317739 commit 30faff5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
6 changes: 4 additions & 2 deletions R/Search_uri.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Search_uri <- function(conn, index=NULL, type=NULL, q=NULL, df=NULL, analyzer=NU
default_operator=NULL, explain=NULL, source=NULL, fields=NULL, sort=NULL,
track_scores=NULL, timeout=NULL, terminate_after=NULL, from=NULL, size=NULL,
search_type=NULL, lowercase_expanded_terms=NULL, analyze_wildcard=NULL,
version=NULL, lenient=FALSE, raw=FALSE, asdf=FALSE,
version=NULL, lenient=FALSE, raw=FALSE, asdf=FALSE, track_total_hits = TRUE,
search_path="_search", stream_opts=list(), ...) {

is_conn(conn)
Expand All @@ -27,14 +27,16 @@ Search_uri <- function(conn, index=NULL, type=NULL, q=NULL, df=NULL, analyzer=NU
search_type = search_type,
lowercase_expanded_terms = lowercase_expanded_terms,
analyze_wildcard = analyze_wildcard, version = as_log(version), q = q,
lenient = as_log(lenient))), raw, asdf, stream_opts, ...)
lenient = as_log(lenient), track_total_hits = ck(track_total_hits))), raw, asdf, stream_opts, ...)
}

search_GET <- function(conn, path, index=NULL, type=NULL, args, raw, asdf,
stream_opts, ...) {
url <- conn$make_url()
url <- construct_url(url, path, index, type)
url <- prune_trailing_slash(url)
# track_total_hits introduced in ES >= 7.0
if (conn$es_ver() < 700) args$track_total_hits <- NULL
# in ES >= v5, lenient param droppped
if (conn$es_ver() >= 500) args$lenient <- NULL
# in ES >= v5, fields param changed to stored_fields
Expand Down
6 changes: 4 additions & 2 deletions R/search.r
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Search <- function(conn, index=NULL, type=NULL, q=NULL, df=NULL, analyzer=NULL,
default_operator=NULL, explain=NULL, source=NULL, fields=NULL, sort=NULL,
track_scores=NULL, timeout=NULL, terminate_after=NULL, from=NULL, size=NULL,
search_type=NULL, lowercase_expanded_terms=NULL, analyze_wildcard=NULL,
version=NULL, lenient=FALSE, body=list(), raw=FALSE, asdf=FALSE,
version=NULL, lenient=FALSE, body=list(), raw=FALSE, asdf=FALSE, track_total_hits = TRUE,
time_scroll=NULL, search_path="_search", stream_opts=list(), ...) {

is_conn(conn)
Expand All @@ -33,7 +33,7 @@ Search <- function(conn, index=NULL, type=NULL, q=NULL, df=NULL, analyzer=NULL,
search_type = search_type,
lowercase_expanded_terms = lowercase_expanded_terms,
analyze_wildcard = analyze_wildcard, version = as_log(version), q = q,
scroll = time_scroll, lenient = as_log(lenient))), body, raw, asdf,
scroll = time_scroll, lenient = as_log(lenient), track_total_hits = ck(track_total_hits))), body, raw, asdf,
stream_opts, ...)
if (!is.null(time_scroll)) attr(tmp, "scroll") <- time_scroll
return(tmp)
Expand All @@ -52,6 +52,8 @@ search_POST <- function(conn, path, index=NULL, type=NULL, args, body, raw,
url <- construct_url(url, path, index, type)
url <- prune_trailing_slash(url)
body <- check_inputs(body)
# track_total_hits introduced in ES >= 7.0
if (conn$es_ver() < 700) args$track_total_hits <- NULL
# in ES >= v5, lenient param droppped
if (conn$es_ver() >= 500) args$lenient <- NULL
# in ES >= v5, fields param changed to stored_fields
Expand Down
8 changes: 8 additions & 0 deletions R/zzz.r
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ as_log <- function(x){
}
}

ck <- function(x){
if (is.null(x) || is.numeric(x)) {
x
} else if (is.logical(x)) {
as_log(x)
}
}

`%|||%` <- function(x, y) if (x == "false") y else x

cl <- function(x) if (is.null(x)) NULL else paste0(x, collapse = ",")
Expand Down
8 changes: 6 additions & 2 deletions man-roxygen/search_par.r
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,13 @@
#' @param analyze_wildcard (logical) Should wildcard and prefix queries be
#' analyzed or not. Default: \code{FALSE}.
#' @param version (logical) Print the document version with each document.
#' @param lenient If \code{TRUE} will cause format based failures (like
#' @param lenient (logical) If \code{TRUE} will cause format based failures (like
#' providing text to a numeric field) to be ignored. Default: \code{FALSE}
#' @param raw (logical) If \code{FALSE} (default), data is parsed to list.
#' @param track_total_hits (logical, numeric) If \code{TRUE} will always track
#' the number of hits that match the query accurately. If \code{FALSE} will
#' count documents accurately up to 10000 documents. If \code{is.integer} will
#' count documents accurately up to the number. Default: \code{TRUE}
#' @param raw (logical) If \code{FALSE} (default), data is parsed to list.
#' If \code{TRUE}, then raw JSON returned
#' @param asdf (logical) If \code{TRUE}, use \code{\link[jsonlite]{fromJSON}}
#' to parse JSON directly to a data.frame. If \code{FALSE} (Default), list
Expand Down

0 comments on commit 30faff5

Please sign in to comment.