我正在玩和学习用于弹性搜索的 scala 和 elastic4s。
我有一个使用官方 elasticsearch 模块的 python 脚本。我在 python 中的代码如下所示:
res=helpers.scan(es, query={"_source": ["http_uri", "header_user_agent"],"query": {"query_string": {"query": "message:key"}}}, index="")
我上面的python代码有效。我得到 90 万个结果,然后处理它们等等。
我正在使用基本的 scala 代码来试用 e4s。这只是一个简单的查询。我的查询错了吗?
import com.sksamuel.elastic4s.ElasticClient
import com.sksamuel.elastic4s.ElasticDsl._
object Banana {
def main(args: Array[String]) {
val client = ElasticClient.local
val res = client execute { search in "*" query "apiKey" } await
println(res.getHits.totalHits)
println(res)
}
}
我运行这个的结果:
info] Running Banana
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
0
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 0,
"successful" : 0,
"failed" : 0
},
"hits" : {
"total" : 0,
"max_score" : 0.0,
"hits" : [ ]
}
}
以及 curl 查询的响应:
$ curl -s 'localhost:9200/_search?q=apiKey&pretty=true' | head -12
{
"took" : 21,
"timed_out" : false,
"_shards" : {
"total" : 1200,
"successful" : 1200,
"failed" : 0
},
"hits" : {
"total" : 756253,
"max_score" : 1.5905869,
"hits" : [ {