token_count
一般integer
类型,并且是作为text
类型的子字段
,它接收字符串后,分析出这个字符串在分词后都多少个token
。token_count
在特定场景还是挺方便的插入一个mapping
,其中length
是name
的子字段。
PUT pigg_test_token
{
"mappings": {
"properties": {
"name": {
"type": "text",
"fields": {
"length": {
"type": "token_count",
"analyzer": "standard"
}
}
}
}
}
}
插入2条数据
PUT pigg_test_token/_doc/1
{ "name": "我可是亚瑟王" }
PUT pigg_test_token/_doc/2
{ "name": "鼓励王" }
PUT pigg_test_token/_doc/3
{ "name": ["亚瑟王", "我爱玩亚瑟"] }
查询name
是3个字的文档
"hits" : [
{
"_index" : "pigg_test_token",
"_type" : "_doc",
"_id" : "2",
"_score" : 1.0,
"_source" : {
"name" : "鼓励王"
}
},
{
"_index" : "pigg_test_token",
"_type" : "_doc",
"_id" : "3",
"_score" : 1.0,
"_source" : {
"name" : [
"亚瑟王",
"我爱玩亚瑟"
]
}
}
]
返回如下:
"hits" : [
{
"_index" : "pigg_test_token",
"_type" : "_doc",
"_id" : "2",
"_score" : 1.0,
"_source" : {
"name" : "鼓励王"
}
},
{
"_index" : "pigg_test_token",
"_type" : "_doc",
"_id" : "3",
"_score" : 1.0,
"_source" : {
"name" : [
"亚瑟王",
"我爱玩亚瑟"
]
}
}
]