0

我正在使用 Elasticsearch 2.x 版本。数据映射如下。

"mappings":{
  "anchor_type": {
    "properties": {
      "image_url": {"type":"string"},
      "vocab": {"type":"nested"}
    }
  }
}

"vocab" 由一个类似的数组组成{string, float}

[ {"human", 0.1}, {"dog", 0.3}, {"cat",0.5}]

我要做的是,当查询“dog”时,我希望最终得分为0.3 / 3,即匹配词的得分除以“vocab”中的项目数。

我使用function_scoreand检索 0.3 工作script_score,但未能获得 3。我认为类似的东西doc['vocab'].value.size()可以工作,但它没有......

有人可以帮我吗?请...

4

1 回答 1

0

我建议在词汇映射中使用token_count。使用多字段映射并到字段的副本,将类型设置为 token_count。您可以参考此字段了解数组的大小。

于 2015-12-08T07:48:44.130 回答