[英]Elasticsearch - how to reflect the number of items in nested field to score?
我正在使用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}]
我想做的是,當查詢“狗”時,我希望最終分數是0.3 / 3,即匹配項的分數除以“ vocab”中的項目數。
我使用function_score
和script_score
檢索了0.3,但未能獲得3。我認為類似doc['vocab'].value.size()
會起作用,但是它沒有...
有人可以幫我嗎? 請...
我建議在vocabs的映射中使用token_count。 使用多字段映射並將其復制到該字段的副本,將類型放置為token_count。 您可以參考此字段以獲取數組大小。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.