I want to download a dataset from elastic in R. Everything works so far.
library(jsonlite)
filter <- paste('"',
"type: type1",
'"',
sep = "")
q <- paste(
'{
"query": {
"query_string" : {
"query" : ', filter,
'}
}
}'
)
My Problem is that I want to filter a new type: /tests/category/task1
I tried:
filter <- paste('"',
"type:/tests/category/task1",
'"',
sep = "")
That gave me the error
Fehler: 400 - all shards failed
ES stack trace:
type: query_shard_exception
reason: Failed to parse query [type:/tests/category/task1]
Then I tried:
filter <- paste('"',
"type: \"/tests/category/task1\" ",
'"',
sep = "")
Producing the Error:
Fehler in check_inputs(body) :
lexical error: probable comment found in input text, comments are not enabled.
ternal-response type: "/tests/category/task1
(right here) ------^
V03:
filter <- paste('"',
"type: \"\/tests\/category\/task1\" ",
'"',
sep = "")
Error:
Fehler: '\/' ist eine unbekannte Escape-Sequenz in der Zeichenkette beginnend mit ""type: \"\/
V04:
filter <- paste('"',
"type: \"\\/tests\\/category\\/task1\" ",
'"',
sep = "")
Error:
Fehler in check_inputs(body) : lexical error: invalid char in json text.
type: "\/tests\/category\/task1"
(right here) ------^
Does anyone know how to handle the / in the query?
Update1:
@hrbrmstr This is the exact code and error
library(jsonlite)
library(elastic)
library(httr)
set_config(config(ssl_verifypeer = FALSE, ssl_verifyhost = FALSE))
connect(
es_host = my_host,
es_port = my_port,
es_transport_schema = "https",
es_user = my_user,
es_pwd = my_pwd,
errors = "complete"
)
mk_query <- function(typ) {
list(
query = list(
query_string = list(
query = list(
type = unbox(typ)
)
)
)
) -> qry
toJSON(qry, pretty=TRUE)
}
q <- mk_query("type1")
res <- Search(
index = my_index,
size = 500,
time_scroll = "1m",
body = q,
raw = FALSE
)
Error:
Fehler: 400 - [query_string] unknown token [START_OBJECT] after [query]
ES stack trace:
type: parsing_exception
reason: [query_string] unknown token [START_OBJECT] after [query]
line: 1
col: 50