elasticsearch是否提供了跟踪热门关键字的方法?例如,在给定的时间段内,我想知道在查询中最常出现的关键字.
如果elasticsearch没有这样的功能,那么使用elasticsearch实现它的好方法是什么?
谢谢!
Tho*_*ten 12
我不认为有一种内置的方式,但通过术语方面实现它应该很容易
你要做的是:
不幸的是,我没有时间给你写一个例子,但这应该会引导你找到解决方案.
这是一个例子:
// Demo index
curl -XDELETE 'http://localhost:9200/queries/'
curl -XPUT 'http://localhost:9200/queries/'
// Add some data
curl -XPUT 'http://localhost:9200/queries/query/1' -d '
{
"date": "2013-02-19T12:57:23",
"query": "Trying out ElasticSearch, so far so good?"
}'
curl -XPUT 'http://localhost:9200/queries/query/2' -d '
{
"date": "2013-03-02T11:27:23",
"query": "Lets give ElasticSearch another try"
}'
curl -XPUT 'http://localhost:9200/queries/query/3' -d '
{
"date": "2013-04-02T08:27:23",
"query": "OK, why dont we stick to SOLR?"
}'
curl -XPUT 'http://localhost:9200/queries/query/4' -d '
{
"date": "2013-04-19T11:27:23",
"query": "Couse ElasticSearch is so much cooler, its bonsai cool"
}'
// Query it
curl -XGET 'http://localhost:9200/queries/query/_search?pretty=true' -d '
{
"query" : {
"filtered" : {
"filter" : {
"range" : {
"date" : {
"gte" : "2013-01-01T00:00:00",
"lt" : "2013-04-01T00:00:00"
}
}
},
"query" : {
"match_all" : {}
}
}
},
"facets": {
"keywords": {
"terms": {
"field": "query"
}
}
}
}
'
Run Code Online (Sandbox Code Playgroud)
调整查询中的日期范围以查看输出的更改
| 归档时间: |
|
| 查看次数: |
6405 次 |
| 最近记录: |