【发布时间】:2019-11-27 15:44:06
【问题描述】:
只返回匹配的源,而不是返回包含该文本的整个弹性搜索文档
假设我有一个这种格式的数据,
POST /bookdb_index/book/_bulk
{ "index": { "_id": 1 }}
{ "title": "Elasticsearch: The Definitive Guide", "authors": ["clinton gormley", "zachary tong"], "summary" : "A distibuted real-time search and analytics engine", "publish_date" : "2015-02-07", "num_reviews": 20, "publisher": "oreilly" }
{ "index": { "_id": 2 }}
{ "title": "Taming Text: How to Find, Organize, and Manipulate It", "authors": ["grant ingersoll", "thomas morton", "drew farris"], "summary" : "organize text using approaches such as full-text search, proper name recognition, clustering, tagging, information extraction, and summarization", "publish_date" : "2013-01-24", "num_reviews": 12, "publisher": "manning" }
{ "index": { "_id": 3 }}
{ "title": "Elasticsearch in Action", "authors": ["radu gheorge", "matthew lee hinman", "roy russo"], "summary" : "build scalable search applications using Elasticsearch without having to do complex low-level programming or understand advanced data science algorithms", "publish_date" : "2015-12-03", "num_reviews": 18, "publisher": "manning" }
{ "index": { "_id": 4 }}
{ "title": "Solr in Action", "authors": ["trey grainger", "timothy potter"], "summary" : "Comprehensive guide to implementing a scalable search engine using Apache Solr", "publish_date" : "2014-04-05", "num_reviews": 23, "publisher": "manning" }
我想搜索包含指南的文本。而不是返回整个文档,我只想拥有那些包含文本查询的字段
GET /bookdb_index/book/_search?q=guide
当我运行它时,它会返回整个文档。但是我只想返回那些包含指南的字段,如摘要指南中的 id 4 中存在,因此只有摘要字段返回,并且标题指南中的 id 1 中存在,所以只有标题是返回
【问题讨论】:
-
我还可以找出文档中搜索文本的计数吗?我的意思是,如果我搜索 quide,我可以计算每个文档中出现 quide 的次数以及在哪个字段中。
-
我已经为您添加了一个答案,如果您想计算每个文档中
guide字符串出现的次数,那么您可以计算字符串匹配的<em>guide</em>的出现次数。希望对你有帮助,祝你好运
标签: elasticsearch kibana elastic-stack amazon-elastic-beanstalk elasticsearch-aggregation