我正在使用名为 token_count 的数据类型
它将计算并存储每个文本的标记数。
此计数值可用于获取具有确切标记数的文档作为搜索文本
PUT testindex6
{
"mappings": {
"properties": {
"search_text": {
"type": "nested",
"properties": {
"text": {
"type": "text",
"fields": {
"length": {
"type": "token_count",
"analyzer": "standard"
}
}
}
}
}
}
}
}
数据:
[
{
"_index" : "testindex6",
"_type" : "_doc",
"_id" : "Il1fDm0B27hOMovb2NOC",
"_score" : 1.0,
"_source" : {
"search_text" : [
{
"text" : "a b c d"
},
{
"text" : "a b c d e"
}
]
}
},
{
"_index" : "testindex6",
"_type" : "_doc",
"_id" : "I11fDm0B27hOMovb99NK",
"_score" : 1.0,
"_source" : {
"search_text" : [
{
"text" : "a b c"
}
]
}
}
]
查询:
GET testindex6/_search
{
"query": {
"nested": {
"path": "search_text",
"query": {
"bool": {
"must": [
{
"match": {
"search_text.text": "b c a"
}
},
{
"term": {
"search_text.text.length": {
"value": 3 ----> pass the number of tokens searched for
}
}
}
]
}
}
}
}
}