[英]How to highlight frequency of keywords in ElasticSearch?
Let's say, I am searching three phrases "Microsoft", "Facebook", "Google". 假设我要搜索三个短语“ Microsoft”,“ Facebook”,“ Google”。
How can I make ES return the frequency of each terms in returned results? 如何使ES返回返回结果中每个术语的频率?
Thank you! 谢谢!
You are probably looking for terms aggregations: 您可能正在寻找术语汇总:
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html https://www.elastic.co/guide/zh-CN/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html
Essentially, it will bucket the results by what terms it finds 本质上,它将按发现的条件对结果进行分类
I think the explain
API may help you. 我认为explain
API可能会对您有所帮助。 If you run the following query for instance: 例如,如果运行以下查询:
GET /your_index/your_type/_search
{
"explain": true,
"query" : {
"match": {
"company" : "Google"
}
}
}
A result may be: 结果可能是:
{
"took": 9,
"timed_out": false,
"_shards": {
"total": 2,
"successful": 2,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 11.7377,
"hits": [
{
"_shard": 1,
"_node": "n0eQxWrIIPYPlmcXA",
"_index": "your_index",
"_type": "your_type",
"_id": "76991",
"_score": 11.7377,
"_source": {
"company": "Google",
"price": "2008"
},
"_explanation": {
"value": 11.7377,
"description": "weight(id:76991 in 6552) [PerFieldSimilarity], result of:",
"details": [
{
"value": 11.7377,
"description": "fieldWeight in 6552, product of:",
"details": [
{
"value": 1,
"description": "tf(freq=1.0), with freq of:",
"details": [
{
"value": 1,
"description": "termFreq=1.0"
}
]
},
{
"value": 11.7377,
"description": "idf(docFreq=2, maxDocs=138180)"
},
{
"value": 1,
"description": "fieldNorm(doc=6552)"
}
]
}
]
}
}
]
}
}
Under the _explanation
section you may see the document frequencies: 在_explanation
部分下,您可能会看到文档频率:
tf - how many times the term repeats in the specific scored document tf-该术语在特定的打分文档中重复多少次
idf - how many times the term repeats along all documents (what you are looking for, I guess) idf-该术语在所有文档中重复多少次(我想您正在寻找什么)
Hope it helps! 希望能帮助到你!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.