elasticsearch - 弹性搜索词计数
问题描述
我的示例弹性索引文档,
{ "_index": "testdata", "_type": "tweet", "_id": > "Dbo5qmMBSUBLqBARJmBG", "_version": 1, "_score": 1, "_source": { > "fileName": "alibaba.pdf", "chapter": "chapter1", "page": 1, > "timeDate": "2018-05-24T11:06:48+00:00", "text": "So why do we > need machine learning, why do we want a machine to learn as a human? > There are many problems involving huge datasets, or complex > calculations for instance, where it makes sense to let computers do > all the work. In general, of course, computers and robots dont get > tired, dont have to sleep, and may be cheaper. There is also an > emerging school of thought called active learning or > human-in-the-loop, which advocates combining the efforts of machine > learners and humans. The idea is that there are routine boring tasks > more suitable for computers, and creative tasks more suitable for > humans.According to this philosophy, machines are able to learn, by > following rules or algorithms designed by humans and to do repetitive
and logic tasks desired by a human" } }
所以我如何计算像 ..machine = 3
等单词humans =2
。
解决方案
您可能想要运行聚合查询。它会是这样的:
{
"aggs" : {
"text_aggregation" : {
"terms" : {
"field" : "text"
}
}
}
}
这将适用于整个索引。如果您想在特定文档上运行它,您可以使用以下内容:
{
"query":{
"match":{
"eventCodes":"ET00075293"
}
},
"aggs" : {
"text_aggregation" : {
"terms" : {
"fileName" : "alibaba.pdf"
}
}
}
}
推荐阅读
- javascript - 尝试...如果函数抛出错误 NodeJS 则捕获
- python - Python:保存数据集时语法无效
- svelte - 苗条的商店安全吗?
- python - 使用来自另一个模块的方法自动扩展类
- angular - 如何不破坏以角度显示选项卡组件?
- spring-mvc - 从@PostMapping 转发到@GetMapping 时,RequestDispatcher#forward() 抛出“不支持请求方法'POST'”
- amazon-web-services - 一段时间后,Alexa 家庭技能请求未达到 lambda 函数
- python - 在python数据框中水平添加特定列中的值
- apache-spark - 使用管道从 S3 加载 Pyspark.ml 模型
- sql - PostgreSQL:`VIEW` 不返回具有`SPLIT_PART()` 列的行