繁体   English   中英

使用Elastic4s进行渗滤器查询

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM