PUT top-terms
{
"index" : {
"analysis" : {
"analyzer" : {
"pinyin_analyzer" : {
"tokenizer" : "my_pinyin"
}
},
"tokenizer" : {
"my_pinyin" : {
"type" : "pinyin",
"keep_first_letter":false,
"keep_separate_first_letter" : true,
"keep_full_pinyin" : false,
"keep_original" : false,
"limit_first_letter_length" : 16,
"lowercase" : true
}
}
}
}
}
PUT top-terms/test/_mapping
{
"properties": {
"title":{
"type": "text",
"analyzer": "pinyin_analyzer",
"fielddata": true
}
}
}
PUT top-terms/test/1
{
"title": "杨俊飞 "
}
PUT top-terms/test/2
{
"title": "俊飞测试"
}
PUT top-terms/test/3
{
"title": "王俊飞"
}
PUT top-terms/test/4
{
"title": "王俊飞测试"
}
GET top-terms/test/_search
{
"aggs": {
"top-terms-aggregation": {
"terms": { "field" : "title","size":5 }
}
}
}
结果:
{
"took": 90,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 4,
"max_score": 1,
"hits": [
{
"_index": "top-terms",
"_type": "test",
"_id": "2",
"_score": 1,
"_source": {
"title": "俊飞测试"
}
},
{
"_index": "top-terms",
"_type": "test",
"_id": "4",
"_score": 1,
"_source": {
"title": "王俊飞测试"
}
},
{
"_index": "top-terms",
"_type": "test",
"_id": "1",
"_score": 1,
"_source": {
"title": "杨俊飞 "
}
},
{
"_index": "top-terms",
"_type": "test",
"_id": "3",
"_score": 1,
"_source": {
"title": "王俊飞"
}
}
]
},
"aggregations": {
"top-terms-aggregation": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 1,
"buckets": [
{
"key": "f",
"doc_count": 4
},
{
"key": "j",
"doc_count": 4
},
{
"key": "c",
"doc_count": 2
},
{
"key": "s",
"doc_count": 2
},
{
"key": "w",
"doc_count": 2
}
]
}
}
}
{
"index" : {
"analysis" : {
"analyzer" : {
"pinyin_analyzer" : {
"tokenizer" : "my_pinyin"
}
},
"tokenizer" : {
"my_pinyin" : {
"type" : "pinyin",
"keep_first_letter":false,
"keep_separate_first_letter" : true,
"keep_full_pinyin" : false,
"keep_original" : false,
"limit_first_letter_length" : 16,
"lowercase" : true
}
}
}
}
}
PUT top-terms/test/_mapping
{
"properties": {
"title":{
"type": "text",
"analyzer": "pinyin_analyzer",
"fielddata": true
}
}
}
PUT top-terms/test/1
{
"title": "杨俊飞 "
}
PUT top-terms/test/2
{
"title": "俊飞测试"
}
PUT top-terms/test/3
{
"title": "王俊飞"
}
PUT top-terms/test/4
{
"title": "王俊飞测试"
}
GET top-terms/test/_search
{
"aggs": {
"top-terms-aggregation": {
"terms": { "field" : "title","size":5 }
}
}
}
结果:
{
"took": 90,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 4,
"max_score": 1,
"hits": [
{
"_index": "top-terms",
"_type": "test",
"_id": "2",
"_score": 1,
"_source": {
"title": "俊飞测试"
}
},
{
"_index": "top-terms",
"_type": "test",
"_id": "4",
"_score": 1,
"_source": {
"title": "王俊飞测试"
}
},
{
"_index": "top-terms",
"_type": "test",
"_id": "1",
"_score": 1,
"_source": {
"title": "杨俊飞 "
}
},
{
"_index": "top-terms",
"_type": "test",
"_id": "3",
"_score": 1,
"_source": {
"title": "王俊飞"
}
}
]
},
"aggregations": {
"top-terms-aggregation": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 1,
"buckets": [
{
"key": "f",
"doc_count": 4
},
{
"key": "j",
"doc_count": 4
},
{
"key": "c",
"doc_count": 2
},
{
"key": "s",
"doc_count": 2
},
{
"key": "w",
"doc_count": 2
}
]
}
}
}
1 个回复
401825317 - 90后it男
赞同来自:
PUT hotwords-1
PUT hotwords-1/_mapping/normal
{
"properties": {
"tags": {
"type": "text",
"index": "true",
"analyzer": "whitespace",
"fielddata": "true"
}
}
}
PUT hotwords-1/normal/1
{
"tags":"三星 "
}
PUT hotwords-1/normal/2
{
"tags":"宝马"
}
PUT hotwords-1/normal/3
{
"tags":"三星"
}
GET hotwords-1/normal/_search
{
"aggregations" : {
"agg" : {
"global" : { },
"aggregations" : {
"all_interests" : {
"terms" : {
"field" : "tags",
"size" : 10,
"shard_size" : 5,
"min_doc_count" : 1,
"shard_min_doc_count" : 0,
"show_term_doc_count_error" : false,
"order" : [
{
"_count" : "desc"
},
{
"_term" : "asc"
}
]
}
}
}
}
},
"ext" : { }
}