[英]How to use aggregations with Elastic Search
我正在使用Elastic Search创建搜索过滤器,并且需要查找“ cambio”列的数据库中保存的所有值,而无需重复这些值。
值按如下方式保存:“ 5月手动设置”或“ 6月手动设置” ....
我创建了此查询以返回所有保存的值:
GET /crawler10/crawler-vehicles10/_search
{
"size": 0,
"aggregations": {
"my_agg": {
"terms": {
"field": "cambio"
}
}
}
}
但是,当我运行返回的值时,它们看起来像这样:
"aggregations": {
"my_agg": {
"doc_count_error_upper_bound": 2,
"sum_other_doc_count": 2613,
"buckets": [
{
"key": "de",
"doc_count": 2755
},
{
"key": "marchas",
"doc_count": 2714
},
{
"key": "manual",
"doc_count": 2222
},
{
"key": "modo",
"doc_count": 1097
},
{
"key": "5",
"doc_count": 1071
},
{
"key": "d",
"doc_count": 1002
},
{
"key": "n",
"doc_count": 1002
},
{
"key": "automática",
"doc_count": 935
},
{
"key": "com",
"doc_count": 919
},
{
"key": "6",
"doc_count": 698
}
]
}
}
聚合基于已保存字段的映射类型。 cambio
的字段类型似乎已设置为analyzed
(默认情况下)。 请建立映射的指数not_analyzed
为您现场cambio
。
您可以使用以下PUT
请求创建索引(如果您的ES版本小于5),则需要在crawler10
索引中重新索引数据。
PUT crawler10/_mapping/
{
"mappings": {
"crawler-vehicles10": {
"properties": {
"cambio": {
"type": "string"
"index": "not_analyzed"
}
}
}
}
}
对于ES v5或更高版本
PUT crawler10/_mapping/
{
"mappings": {
"crawler-vehicles10": {
"properties": {
"cambio": {
"type": "keyword"
}
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.