[英]Using Elastic4s for Percolator Queries
我目前正在嘗試使用Elastic4s創建一個滲濾器查詢。 我已經了解了很多,但是似乎找不到任何示例,因此我不確定這是如何工作的。 所以我有:
val percQuery = percolate in esIndex / esType query myQuery
esClient.execute(percQuery)
每次運行它都不匹配任何東西。 我發現我需要能夠對一個ID進行過濾,但是我似乎找不到任何示例,甚至在文檔中也沒有。 我知道使用Elastic4s創建除滲濾器查詢之外的查詢可以讓您指定一個id字段,例如:
val query = index into esIndex / esType source myDoc id 12345
我已經嘗試過這種滲濾方法,但是它不喜歡id字段,有人知道該怎么做嗎?
我以前曾使用Dispatch Http來執行此操作,但我正試圖擺脫它。 之前,我這樣做是為了提交過濾器查詢:
url(s"$esUrl/.percolator/$queryId)
.setContentType("application/json", "utf-8")
.setBody(someJson)
.POST
注意queryId只是需要類似的東西,但是在elastic4s中。
因此,您想添加一個文檔並返回等待添加該id
的查詢嗎? 滲濾似乎是一種奇怪的用途,因為它只能使用一次,因為每個id只能添加一個文檔。 您目前無法在elastic4s中的id上進行滲濾,而且我不確定是否可以在elasticsearch本身中進行滲濾。
這是我可以嘗試的最佳嘗試,在這里您有自己的“ id”字段,該字段可以反映“ proper” _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編寫
因此,在進行了更多研究之后,我弄清楚了它如何與elastic4s配合使用。 要在Elastic4s中做到這一點,您實際上必須使用register而不是像這樣的滲濾 :
val percQuery = register id queryId into esIndex query myQuery
這將在id處注冊一個滲濾器查詢。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.