elasticsearch-percolate,Scala,Elastic4s,elasticsearch Percolate" /> elasticsearch-percolate,Scala,Elastic4s,elasticsearch Percolate" />

Scala 使用Elastic4s进行Percolator查询

Scala 使用Elastic4s进行Percolator查询,scala,elastic4s,elasticsearch-percolate,Scala,Elastic4s,elasticsearch Percolate,我目前正在尝试使用Elastic4s创建一个percolator查询。到目前为止,我已经知道了,但我似乎找不到任何例子,所以我不确定这到底是怎么回事。所以我有: val percQuery = percolate in esIndex / esType query myQuery esClient.execute(percQuery) 每次运行时,它都不匹配任何内容。我发现我需要能够在一个Id上进行过滤,但我似乎找不到任何关于如何进行过滤的例子,甚至在文档中也找不到。我知道,通过Elasti

我目前正在尝试使用Elastic4s创建一个percolator查询。到目前为止,我已经知道了,但我似乎找不到任何例子,所以我不确定这到底是怎么回事。所以我有:

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

请注意,查询id只需要与之类似的东西,但在elastic4s中是这样的。

那么您想添加一个文档并返回等待添加该
id
的查询吗?对于percolate来说,这似乎是一个奇怪的用途,因为它只能一次性使用,因为每个id只能添加一个文档。在elastic4s中,您目前无法在id上执行percolate,我不确定您是否可以在elasticsearch中执行

这是我能想到的最好的尝试,您有自己的“id”字段,它可以镜像“正确的”
\u 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编写,因此您希望添加文档并返回等待添加该
id
的查询?对于percolate来说,这似乎是一个奇怪的用途,因为它只能一次性使用,因为每个id只能添加一个文档。在elastic4s中,您目前无法在id上执行percolate,我不确定您是否可以在elasticsearch中执行

这是我能想到的最好的尝试,您有自己的“id”字段,它可以镜像“正确的”
\u 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中实现这一点,您实际上必须使用寄存器,而不是像这样使用渗滤液:


这将在id处注册一个percolator查询。

因此,经过更多的研究,我找到了如何使用elastic4s。要在Elastic4s中实现这一点,您实际上必须使用寄存器,而不是像这样使用渗滤液:


这将在id处注册一个percolator查询。

我以前使用Dispatch Http来完成这项工作,但我正在尝试远离它。之前,我这样做是为了提交percolator查询:
url(s“$esUrl/.percolator/$queryId)
注意,查询ID只需要类似的东西。你认为这仍然是最好的方法吗?我以前使用Dispatch Http来完成这项工作,但我正在尝试远离它。在此之前,我这样做是为了提交percolator查询:
url(s“$esUrl/.percolator/$queryId)
注意,查询ID只需要类似的东西。你认为这仍然是最好的方法吗?注册就是注册你的查询。Percolate是添加文档并查看其匹配的已注册查询的行为。我认为这个术语与Elasticsearch是一致的,注册就是注册你的查询。Percolate是添加文档并查看其匹配的已注册查询的行为。我认为术语与Elasticsearch一致,