【问题标题】:Elasticsearch nested filtering (elastic4s, scala)Elasticsearch 嵌套过滤(elastic4s、scala)
【发布时间】:2016-12-20 16:54:25
【问题描述】:

我正在使用 Elasticsearch 1.7 和 elastic4s DSL。 我的问题是我无法在嵌套文档上添加和 & 或过滤器。 例如,这是我的案例类 Candidate 实例的 JSON 表示:

{
  "name": "Samy"
  "interviews": [
    {
      "clientId": 0,
      "stateId": "CANCELED",
    },
    {
      "clientId": 1,
      "stateId": "APPROVED"
    }
  ]

这是我的过滤器:

def filtering(interviewAndCandidates: IntCand)(implicit user: PublicUser): Seq[FilterDefinition] = {
nestedFilter("interviews").filter(termFilter("clientId", user.id)) ::
List(or(interviewAndCandidates.interviews.map(state ⇒ nestedFilter("interviews").filter(termFilter("stateId", state)))))
}

然后我构建查询:

var request: SearchDefinition = search in "myIndex" -> "candidate" query {
  filteredQuery query {
    matchAllQuery
  } filter {
    and(filters)
  }
}

与:

case class IntCand(interviews: List[String])

case class Candidate(name: String, interviews: List[Interview])

case class Interview(clientId: Long, stateId: String)

问题是当我过滤 IntCand(List("CANCELED")) 和 clientId=1 时,响应显示我候选人(我想过滤 clientId 和采访)

【问题讨论】:

    标签: scala elasticsearch elastic4s


    【解决方案1】:

    我通过非规范化数据成功了

    【讨论】:

      猜你喜欢
      • 2017-07-27
      • 1970-01-01
      • 2018-01-30
      • 2014-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-14
      相关资源
      最近更新 更多