[英]Elasticsearch: Having document score equal number of hits in field
Using elasticsearch, I'm searching through an index on a field that typically has a large amount of text and I simply want to know the number of times the query was matched per document. 使用elasticsearch,我正在搜索通常具有大量文本的字段上的索引,而我只想知道每个文档匹配查询的次数。 Anyone know of a good way to do this?
有人知道这样做的好方法吗? I'd like to do it through the score value if possible.
如果可能的话,我想通过分数值来做。 So for example, if I searched "fox" on "the quick brown fox jumped over the lazy fox", I'd get something that includes:
因此,例如,如果我在“快速的棕色狐狸跳过了懒惰的狐狸”上搜索了“狐狸”,则会得到以下内容:
"_score" : 2.0 “ _score”:2.0
The default scoring model also account this into picture , but then this is not the only thing accounts. 默认的评分模型也将其记入图片,但这并不是唯一的说明。 What you are looking for is called term frequency.
您要寻找的是术语频率。 The default scoring model is based on TF-IDF ( Term frequency and inverse document frequency) and also field length.
默认评分模型基于TF-IDF(术语频率和文档反向频率)以及字段长度。 You can read more about it here .
您可以在此处了解更多信息。
Now coming back to your requirement , you can use the scripting module and function score query 现在回到您的需求,您可以使用脚本模块和功能得分查询
{
"query": {
"function_score": {
"query": {
"match": {
"field": "fox"
}
},
"boost_mode": "replace",
"functions": [
{
"script_score": {
"script": "_index['field']['fox'].tf()"
}
}
]
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.