是时候用 ES 拯救发际线啦

terms聚合不区分大小写

Elasticsearch | 作者 zhaohao | 发布于2018年03月23日 | 阅读数:6836

插入数据
curl -XPOST '192.168.2.58:9200/test_index1/test_type1/_bulk?pretty' -H 'Content-Type: application/json' -d'
{ "index": {}}
{ "appid" : "hello", "num": 1}
{ "index": {}}
{ "appid" : "Hello", "num": 2}
{ "index": {}}
{ "appid" : "hEllo", "num": 3}
{ "index": {}}
{ "appid" : "HELLO", "num": 4}
'
聚合
curl -XPOST "http://192.168.2.58:9200/test_index1/_search" -H 'Content-Type: application/json' -d'
{
  "aggregations": {
    "appids": {
      "terms": {
        "field": "appid"
      }
    }
  },
  "size": 0
}'
结果
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 6,
"successful": 6,
"failed": 0
},
"hits": {
"total": 4,
"max_score": 0,
"hits": []
},
"aggregations": {
"appids": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "hello",
"doc_count": 4
}
]
}
}
}
聚合结果怎么不区分大小写?
单独查询
curl -XPOST "http://192.168.2.58:9200/test_index1/_search" -H 'Content-Type: application/json' -d'
{
"query":{
"match_all":{

}
}
}'
结果
{
"took": 6,
"timed_out": false,
"_shards": {
"total": 6,
"successful": 6,
"failed": 0
},
"hits": {
"total": 4,
"max_score": 1,
"hits": [
{
"_index": "test_index1",
"_type": "test_type1",
"_id": "AWJRl1hmXqrE9rKRDqC9",
"_score": 1,
"_source": {
"appid": "hello",
"num": 1
}
},
{
"_index": "test_index1",
"_type": "test_type1",
"_id": "AWJRl1hnXqrE9rKRDqDA",
"_score": 1,
"_source": {
"appid": "HELLO",
"num": 4
}
},
{
"_index": "test_index1",
"_type": "test_type1",
"_id": "AWJRl1hnXqrE9rKRDqC-",
"_score": 1,
"_source": {
"appid": "Hello",
"num": 2
}
},
{
"_index": "test_index1",
"_type": "test_type1",
"_id": "AWJRl1hnXqrE9rKRDqC_",
"_score": 1,
"_source": {
"appid": "hEllo",
"num": 3
}
}
]
}
}
聚合结果都变成小写的了,为什么不区分大小写?
单独查询数据区分大小写的。。。
已邀请:

rockybean - Elastic Certified Engineer, ElasticStack Fans,公众号:ElasticTalk

赞同来自: zhaohao rochy

这个和你的分词有关
 
如果是 keyword,可以用 normalizer 来设定下
https://www.elastic.co/guide/e ... .html

要回复问题请先登录注册