Farid ullah
Farid ullah

Reputation: 291

NA/NaN argument Error in creating json in R

I want to query data from elastic search in R.

library(elasticsearch)
query <- query('{"match": {"drv_age" : 63}}')
data <- elastic("http://localhost:9200", "acturial", "data") %search% query

It works fine, but I want to do this in the following way because I am setting parameters from command line.

index.name <- "acturial"
index.type <- "data"  
col.name <- "drv_age"  
value <- "63"  
query <- query({"match": {col.name : value}}) 
data <- elastic("http://localhost:9200", index.name, index.type) %search% query

It gives me the following error

Error in col.name:value : NA/NaN argument

Upvotes: 2

Views: 710

Answers (1)

SymbolixAU
SymbolixAU

Reputation: 26258

To create a string from objects in R you need to use a function like paste0()

For example,

qry <- paste0('{ "match" : {"', col.name, '" : ', value , '} } '), 

will give you your query string, and then use this inside query as

query <- query(qry)

Upvotes: 1

Related Questions