ElasticSearch 统计搜索热词

实际开发中,我们会统计某个模块下的搜索热词,这个在elasticsearch中特别好用,也比较简单,

使用可以使用 "terms aggregation" 来统计热词

terms 是代表的elasticSerach中的Term Query,统计的就是Term Query,

Term Query是一种最基本的查询方式,它用于在Elasticsearch中查询一个字段中包含指定关键词的文档,与MySQL中的等值查询类似。使用Term Query时,可以对字段进行完全匹配,且区分大小写。

如下:

GET /{index}/_search
{
    "query": {
        "term": {
            "{field}": "{value}"
        }
    }
}

 举个例子:查询需求模块下的title=2的数据

GET /robot-demand/_search
{
    "query": {
        "term": {
            "title": "2"
        }
    }
}

查询结果如下:

猜你喜欢

转载自blog.csdn.net/weixin_38225763/article/details/134113146