世界上并没有完美的程序,但是我们并不因此而沮丧,因为写程序就是一个不断追求完美的过程。
问 :normalizer有什么特点?
答 :
问 :normalizer如何使用?
答 :
# normalizer
PUT /normalizer_test
{
"settings" : {
"analysis" : {
"normalizer" : {
"my_normalizer" : {
"type" : "custom",
"char_filter" : {},
"filter" : ["lowercase", "asciifolding"]
}
}
}
},
"mappings" : {
"properties": {
"name" : {
"type" : "keyword",
"normalizer" : "my_normalizer"
}
}
}
}
# 索引
POST /normalizer_test/_doc/1
{
"name" : "BÀR"
}
# 索引
POST /normalizer_test/_doc/2
{
"name" : "bar"
}
# 索引
POST /normalizer_test/_doc/3
{
"name" : "Bar"
}
# 搜索
GET /normalizer_test/_search
{
"query" : {
"term" : {
"name" : "BAR"
}
}
}
# 结果
{
"took" : 11,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 3,
"relation" : "eq"
},
"max_score" : 0.13353139,
"hits" : [
{
"_index" : "normalizer_test",
"_type" : "_doc",
"_id" : "1",
"_score" : 0.13353139,
"_source" : {
"name" : "BÀR"
}
},
{
"_index" : "normalizer_test",
"_type" : "_doc",
"_id" : "2",
"_score" : 0.13353139,
"_source" : {
"name" : "bar"
}
},
{
"_index" : "normalizer_test",
"_type" : "_doc",
"_id" : "3",
"_score" : 0.13353139,
"_source" : {
"name" : "Bar"
}
}
]
}
}
# 聚合
GET /normalizer_test/_search
{
"aggs": {
"normalizer_aggs" : {
"terms" : {
"field" : "name",
"size" : 10
}
}
}
}
# 结果
{
"took" : 11,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 3,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "normalizer_test",
"_type" : "_doc",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"name" : "BÀR"
}
},
{
"_index" : "normalizer_test",
"_type" : "_doc",
"_id" : "2",
"_score" : 1.0,
"_source" : {
"name" : "bar"
}
},
{
"_index" : "normalizer_test",
"_type" : "_doc",
"_id" : "3",
"_score" : 1.0,
"_source" : {
"name" : "Bar"
}
}
]
},
"aggregations" : {
"normalizer_aggs" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "bar",
"doc_count" : 3
}
]
}
}
}
复制代码
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END