赞
踩
elasticsearch version: 7.10.1
match_phrase_prefix 是 Elasticsearch 中的一个查询类型,它用于执行前缀匹配短语查询。它允许你找到以特定短语开始的文档,而不是仅仅匹配单个单词的前缀。
{
"match_phrase_prefix": {
"field_name": {
"query": "your_phrase_prefix",
"max_expansions": 50
}
}
}
查询product_name 字段以 “apple i” 开头的文档
PUT /products_index
{
"mappings": {
"properties": {
"product_name": {
"type": "text"
}
}
}
}
POST /products_index/_doc/1
{
"product_name": "Apple iPhone 13"
}
POST /products_index/_doc/2
{
"product_name": "Apple iPad Pro"
}
POST /products_index/_doc/3
{
"product_name": "Samsung Galaxy S21"
}
GET /products_index/_search
{
"query": {
"match_phrase_prefix": {
"product_name": {
"query": "apple i"
}
}
}
}
GET /products_index/_search
{
"query": {
"match_phrase_prefix": {
"product_name": {
"query": "apple",
"max_expansions": 1
}
}
}
}
在这个查询中,我们设置了 max_expansions 为 1,这意味着查询将只展开为最多一个前缀。因此,这个查询可能只返回 “Apple iPhone 13”,因为它是在索引中遇到的第一个以 “apple” 开头的 product_name。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。