elasticsearch 按令牌计数使用筛选器进行搜索
分析文档中的字段,以创建令牌
elasticsearch 按令牌计数使用筛选器进行搜索,
elasticsearch,token,
elasticsearch,Token,分析文档中的字段,以创建令牌 {“message”:“hello world”}->令牌:[“hello”,“world”] {“message”:“hello”}->令牌:[“hello”] {“消息”:“世界”}->令牌:[“世界”] {“message”:“hello java”}->令牌:[“hello”,“java”] {“message”:“java”}->令牌:[“java”] 是否可以搜索特定字段中包含给定标记和1个或多个其他标记的所有文档 令牌“hello”的给定示例的结果为
{“message”:“hello world”}
->令牌:[“hello”,“world”]{“message”:“hello”}
->令牌:[“hello”]{“消息”:“世界”}
->令牌:[“世界”]{“message”:“hello java”}
->令牌:[“hello”,“java”]{“message”:“java”}
->令牌:[“java”]- 令牌“hello”的给定示例的结果为:
- 1,4
- 对于“世界”:
- 一,
如果有人能帮忙,那就太好了。是的,你可以用这个类型。例如,在映射中,可以将
message
定义为多字段,以包含消息本身(即“hello”、“hello world”等)以及消息的令牌数。然后,您将能够在查询中包含对字数的约束
因此,消息
的映射应如下所示:
curl -XPUT localhost:9200/tests -d '
{
"mappings": {
"test": {
"properties": {
"message": {
"type": "string", <--- message is a normal analyzed string
"fields": {
"word_count": { <--- a sub-field to include the word count
"type": "token_count",
"store": "yes",
"analyzer": "standard"
}
}
}
}
}
}
}
类似地,如果在上述查询中将hello
替换为world
,则只会得到hello world
curl -XPOST localhost:9200/tests/test/_search -d '
{
"query": {
"bool": {
"must": [
{
"match": {
"message": "hello"
}
},
{
"range": {
"message.word_count": {
"gt": 1
}
}
}
]
}
}
}