我目前正在尝试用Elastic4s创建一个过滤查询。我已经做到了这一点,但我似乎找不到任何例子,所以我不确定这是如何工作的。所以我得到了:
val percQuery = percolate in esIndex / esType query myQuery
esClient.execute(percQuery)每次运行它都不匹配任何内容。我想我需要能够过滤一个Id,但我似乎找不到任何关于如何做到这一点的例子,甚至在文档中也找不到。我知道使用Elastic4s创建查询而不是percolator查询可以让您指定一个id字段,如下所示:
val query = index into esIndex / esType source myDoc id 12345我试过用这种方法来过滤,但它不像id字段,有人知道怎么做吗?
我之前使用Dispatch Http来做这件事,但我正试图摆脱它。之前,我这样做是为了提交percolator查询:
url(s"$esUrl/.percolator/$queryId)
.setContentType("application/json", "utf-8")
.setBody(someJson)
.POST请注意,在elastic4s中,queryId只需要类似的内容。
发布于 2015-12-22 16:19:27
因此,您想添加一个文档并返回等待添加该id的查询吗?这似乎是percolate的一种奇怪用法,因为它只能使用一次,因为每个id只能添加一个文档。你目前不能在elastic4s中对id做过滤,我甚至不确定你是否可以在elasticsearch本身做。
这是我能想到的最好的尝试,其中你有你自己的"id“字段,它可以反映”正确的“_id字段。
object Test extends App {
import ElasticDsl._
val client = ElasticClient.local
client.execute {
create index "perc" mappings {
"idtest" as(
"id" typed StringType
)
}
}.await
client.execute {
register id "a" into "perc" query {
termQuery("id", "a")
}
}.await
client.execute {
register id "b" into "perc" query {
termQuery("id", "b")
}
}.await
val resp1 = client.execute {
percolate in "perc/idtest" doc("id" -> "a")
}.await
// prints a
println(resp1.getMatches.head.getId)
val resp2 = client.execute {
percolate in "perc/idtest" doc("id" -> "b")
}.await
// prints b
println(resp2.getMatches.head.getId)
}使用elastic4s 1.7.4编写
发布于 2015-12-23 01:46:32
因此,经过更多的研究,我弄清楚了这是如何与elastic4s一起工作的。要在Elastic4s中做到这一点,您实际上必须使用register而不是percolate,如下所示:
val percQuery = register id queryId into esIndex query myQuery这将在id处注册一个过滤器查询。
https://stackoverflow.com/questions/34405463
复制相似问题