令牌计数字段类型
1.0 版引入
令牌计数字段类型存储字符串中分析后的令牌数量。
示例
创建带有令牌计数字段的映射
PUT testindex
{
"mappings": {
"properties": {
"sentence": {
"type": "text",
"fields": {
"num_words": {
"type": "token_count",
"analyzer": "english"
}
}
}
}
}
}
索引三个带有文本字段的文档
PUT testindex/_doc/1
{ "sentence": "To be, or not to be: that is the question." }
PUT testindex/_doc/2
{ "sentence": "All the world’s a stage, and all the men and women are merely players." }
PUT testindex/_doc/3
{ "sentence": "Now is the winter of our discontent." }
搜索少于 10 个词的句子
GET testindex/_search
{
"query": {
"range": {
"sentence.num_words": {
"lt": 10
}
}
}
}
响应包含一个匹配的句子
{
"took" : 8,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "testindex",
"_type" : "_doc",
"_id" : "3",
"_score" : 1.0,
"_source" : {
"sentence" : "Now is the winter of our discontent."
}
}
]
}
}
参数
下表列出了令牌计数字段类型接受的参数。analyzer
参数是必需的;所有其他参数都是可选的。
参数 | 描述 |
---|---|
分析器 | 此字段要使用的分析器。为获得最佳性能,请指定不带令牌过滤器的分析器。必填。 |
提升 | 一个浮点值,指定此字段对相关性得分的权重。高于 1.0 的值会增加字段的相关性。介于 0.0 和 1.0 之间的值会降低字段的相关性。默认值为 1.0。 |
doc_values | 一个布尔值,指定字段是否应存储在磁盘上,以便用于聚合、排序或脚本编写。默认值为 false 。 |
enable_position_increments | 一个布尔值,指定是否应计算位置增量。为避免删除停用词,请将此字段设置为 false 。默认值为 true 。 |
索引 | 一个布尔值,指定字段是否可搜索。默认值为 true 。 |
null_value | 一个用于替换 null 的值。必须与字段类型相同。如果未指定此参数,则当其值为 null 时,该字段将被视为缺失。默认值为 null 。 |
存储 | 一个布尔值,指定字段值是否应存储且可与 _source 字段单独检索。默认值为 false 。 |