[英]Retrieving top terms query in Elasticsearch
I am using Elasticsearch 1.1.0 and trying to retrieve the top 10 terms in a field called text
我正在使用 Elasticsearch 1.1.0 并尝试在名为text
的字段中检索前 10 个术语
I've tried the following, but it instead returned all of the documents:我尝试了以下操作,但它返回了所有文档:
{
"query": {
"match_all": {}
},
"facets": {
"text": {
"terms": {
"field": "text",
"size": 10
}
}
}
}
EDIT编辑
the following is an example of the result that is returned:以下是返回结果的示例:
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 2747,
"max_score": 1,
"hits": [
{
"_index": "index_name",
"_type": "type_name",
"_id": "621637640908050432",
"_score": 1,
"_source": {
"metadata": {
"result_type": "recent",
"iso_language_code": "en"
},
"in_reply_to_status_id_str": null,
"in_reply_to_status_id": null,
"created_at": "Thu Jul 16 11:08:57 +0000 2015",
.
.
.
.
What am I doing wrong?我究竟做错了什么?
Thanks.谢谢。
First of all, don't use facets
.首先,不要使用facets
。 They are deprecated.它们已被弃用。 Even though you use OLD version of Elasticsearch, switch to aggregations.即使您使用旧版本的 Elasticsearch,也请切换到聚合。 Quoting documentation:引用文档:
Faceted search refers to a way to explore large amounts of data by displaying summaries about various partitions of the data and later allowing to narrow the navigation to a specific partition.分面搜索是指通过显示有关数据的各个分区的摘要,然后允许将导航范围缩小到特定分区来探索大量数据的方法。
In Elasticsearch, facets are also the name of a feature that allowed to compute these summaries.在 Elasticsearch 中,facet 也是允许计算这些摘要的功能的名称。 facets have been replaced by aggregations in Elasticsearch 1.0, which are a superset of facets.在 Elasticsearch 1.0 中,facet 已被聚合取代,聚合是 facet 的超集。
Use this query instead:请改用此查询:
POST /your_index/your_type/_search?search_type=count
{
"aggs" : {
"text" : {
"terms" : {
"field" : "text",
"size" : 10
}
}
}
}
This will work fine这将正常工作
Try this:尝试这个:
GET /index_name/type_name/_search?search_type=count
{
"query": {
"match_all": {}
},
"facets": {
"text": {
"terms": {
"field": "text",
"size": 10
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.