gpt4 book ai didi

r - extract_function(initial_response)中的错误:R中的elasticsearchr中没有返回查询结果

转载 作者:行者123 更新时间:2023-12-02 22:57:31 25 4
gpt4 key购买 nike

我在 flex 搜索中有一个索引,希望得到特定的驾驶员年龄人士。我执行以下查询以获取drv_age = 63

library(elasticsearchr)

# Required variables;
index.name <- "acturial"
index.type <- "data"
col.name <- "drv_age"
value <- 63

# Path where result will be written in json form;
path <- "G:\\R Projects\\Elastic Search R\\Record.json"

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

# reading data from elasticSearch
data <- elastic("http://localhost:9200", index.name, index.type) %search% query(myQuery)

它工作正常,但是当我将drv_age = 10000放在索引中时,它给了我

Error in extract_function(initial_response) : no query results returned



我的问题是将该错误消息存储在变量中以对其进行处理。但是我做不到。

最佳答案

使用R中 flex 包装的搜索方法,我们可以获得针对某个查询的总点击量。这样,我们可以检查是否找到任何数据。以下是代码段。

library(elastic)

connect()

# Required variables;
index.name <- "acturial"
index.type <- "data"
col.name <- "year"
value <- "2013"

myQuery <- paste(col.name,value,sep = ":")

records.found <- Search(index.name,index.type,q=myQuery)$hits$total

if (records.found > 0){
# Your loggic;
}else{
print("No record found")
}

关于r - extract_function(initial_response)中的错误:R中的elasticsearchr中没有返回查询结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47261392/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com