es-mapping-parameters-4

16.index_prefixes 前缀搜索

  • 提升prefix的查询速度。
  • 搭配text类型

配置:

  1. min_chars:前缀最小长度,>0,默认2
  2. max_chars:前缀最大长度,<20,默认5
DELETE my-index-000001
PUT /my-index-000001
{
   
  "mappings": {
   
    "properties": {
   
      "name": {
   
        "type": "text",
        "index_prefixes": {
   
          "min_chars": 3,
          "max_chars": 6
        },
        "fields": {
   
          "keyword": {
   
            "type": "keyword"
          }
        }
      }
    }
  }
}

# 索引
POST /my-index-000001/_doc/1
{
   
  "name" : "attractive girl"
}

POST /my-index-000001/_doc/2
{
   
  "name" : "self-confidence attractiveness"
}


# 搜索attractive的前面几个单词at att attr,g
# 查询at:错误:query_shard_exception,failed to create query: Cannot invoke \"Object.hashCode()\" because \"this.rewriteMethod\" is null
# 查询att,attr:两条记录
# 查询attractive:两条记录
# attractiveness:一条记录
GET /my-index-000001/_search
{
   
  "query" : {
   
    "prefix" : {
   
      "name" : {
   
        "value" : "attr"
      }
    }
  }
}

#不加index_prefixes 前缀默认:2-5
DELETE my-index-000001
PUT /my-index-000001
{
   
  "mappings": {
   
    "properties": {
   
      "name": {
   
        "type": "text",
        "fields": {
   
          "keyword": {
   
            "type": "keyword"
          }
        }
      }
    }
  }
}

# 索引
POST /my-index-000001/_doc/1
{
   
  "name" : "attractive girl"
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值