NipGeihou's blog NipGeihou's blog
  • Java

    • 开发规范
    • 进阶笔记
    • 微服务
    • 快速开始
    • 设计模式
  • 其他

    • Golang
    • Python
    • Drat
  • Redis
  • MongoDB
  • 数据结构与算法
  • 计算机网络
  • 应用

    • Grafana
    • Prometheus
  • 容器与编排

    • KubeSphere
    • Kubernetes
    • Docker Compose
    • Docker
  • 组网

    • TailScale
    • WireGuard
  • 密码生成器
  • 英文单词生成器
🍳烹饪
🧑‍💻关于
  • 分类
  • 标签
  • 归档

NipGeihou

我见青山多妩媚,料青山见我应如是
  • Java

    • 开发规范
    • 进阶笔记
    • 微服务
    • 快速开始
    • 设计模式
  • 其他

    • Golang
    • Python
    • Drat
  • Redis
  • MongoDB
  • 数据结构与算法
  • 计算机网络
  • 应用

    • Grafana
    • Prometheus
  • 容器与编排

    • KubeSphere
    • Kubernetes
    • Docker Compose
    • Docker
  • 组网

    • TailScale
    • WireGuard
  • 密码生成器
  • 英文单词生成器
🍳烹饪
🧑‍💻关于
  • 分类
  • 标签
  • 归档
  • 消息队列

  • 搜索引擎

    • ElasticSearch

      • 概述
      • 环境搭建
      • 操作 - Restful
      • 操作 - RestClinet(弃用)
      • 操作 - Spring Data
      • 示例 - 黑马旅游
        • 自动补全
          • 修改酒店映射结构
          • 测试自动补全
      • 查询 - 数据聚合
      • ElasticSearch - 自动补全与自定义分词器
      • ElasticSearch - 数据同步
      • ElasticSearch - 集群
  • 中间件
  • 搜索引擎
  • ElasticSearch
NipGeihou
2022-05-07
目录

示例 - 黑马旅游

NipGeihou/hotel-demo

# 自动补全

# 修改酒店映射结构

// 酒店数据索引库
PUT /hotel
{
  "settings": {
    "analysis": {
      "analyzer": {
          // 自定义分词器1:分词后转拼音(用于全文检索)
        "text_anlyzer": {
          "tokenizer": "ik_max_word",
          "filter": "py"
        },
          // 自定义分词器2:不分词转拼音(用于自动补全)
        "completion_analyzer": {
          "tokenizer": "keyword",
          "filter": "py"
        }
      },
      "filter": {
         // 分词过滤器:py
        "py": {
          "type": "pinyin",
          "keep_full_pinyin": false,
          "keep_joined_full_pinyin": true,
          "keep_original": true,
          "limit_first_letter_length": 16,
          "remove_duplicated_term": true,
          "none_chinese_pinyin_tokenize": false
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "id":{
        "type": "keyword"
      },
      "name":{
        "type": "text",
        "analyzer": "text_anlyzer",
        "search_analyzer": "ik_smart",
        "copy_to": "all"
      },
      "address":{
        "type": "keyword",
        "index": false
      },
      "price":{
        "type": "integer"
      },
      "score":{
        "type": "integer"
      },
      "brand":{
        "type": "keyword",
        "copy_to": "all"
      },
      "city":{
        "type": "keyword"
      },
      "starName":{
        "type": "keyword"
      },
      "business":{
        "type": "keyword",
        "copy_to": "all"
      },
      "location":{
        "type": "geo_point"
      },
      "pic":{
        "type": "keyword",
        "index": false
      },
      "all":{
        "type": "text",
        "analyzer": "text_anlyzer",
        "search_analyzer": "ik_smart"
      },
        // 用于自动补全
      "suggestion":{
          "type": "completion",
          "analyzer": "completion_analyzer"
      }
    }
  }
}

# 测试自动补全

GET /hotel/_search
{
  "suggest": {
      // 自定义补全名称
    "suggestions": {
        // 输入内容
      "text": "h",
        "completion": {
        "field": "suggestion", 
            // 跳过重复
        "skip_duplicates": true, 
        "size": 10 
      }
    }
  }
}
上次更新: 2023/05/20, 16:38:38
操作 - Spring Data
查询 - 数据聚合

← 操作 - Spring Data 查询 - 数据聚合→

最近更新
01
Docker Swarm
04-18
02
安全隧道 - gost
04-17
03
Solana最佳实践
04-16
更多文章>
Theme by Vdoing | Copyright © 2018-2025 NipGeihou | 友情链接
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式