20 01 2023

elasticSearch 相关说明

作用:elasticSearch的作用就是用来检索文章的。

docker run -d \
	--name es \
    -e "ES_JAVA_OPTS=-Xms512m -Xmx512m" \
    -e "discovery.type=single-node" \
    -v es-data:/usr/share/elasticsearch/data \
    -v es-plugins:/usr/share/elasticsearch/plugins \
    --privileged \
    --network es-net \
    -p 9200:9200 \
    -p 9300:9300 \
elasticsearch:7.12.1

以上是docker启动es容器的命令,512M是对内存大小的配置,建议最小配置为512M,否则有可能功能不能正常使用,后面是对数据卷的加载,第一个是加载数据目录,第二个是加载插件目录。--network 是加入同一个网络。如果要部署kibana(可视化工具)的话,需要在同一个网络。

docker network create es-net


docker run -d \
--name kibana \
-e ELASTICSEARCH_HOSTS=http://es:9200 \
--network=es-net \
-p 5601:5601  \
kibana:7.12.1

以上是kibana的docker容器启动命令,配置一下es的连接地址即可。为了达到更好的分词效果es需要安装ik分词器 github 官方地址 ,以及拼音分词器 github 官方地址 。安装完这两个插件,需要重启es和kibana的服务。

application.yml配置文件es相关配置:

application.yml es配置文件

第一步需要在test包里面执行这个创建索引库的方法cc.langhai.es.ESTest#createHotelIndex。

第二步需要在test包里面执行初始化数据,也就是将现在mysql里面的文章全部添加到es搜索引擎当中,cc.langhai.es.ESTest#testBulkRequest。

一些es的代码相关操作在这个包里面cc.langhai.mq.service.ESService。


以下是相关的DSL语句。

# 浪海博客系统数据索引库
PUT /langhaiblogs
{
  "settings": {
    "analysis": {
      "analyzer": {
        "text_anlyzer": {
          "tokenizer": "ik_max_word",
          "filter": "py"
        }
      },
      "filter": {
        "py": {
          "type": "pinyin",
          "keep_full_pinyin": true,
          "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"
      },
      "title":{
        "type": "text",
        "analyzer": "text_anlyzer",
        "search_analyzer": "ik_smart"
      },
      "userId":{
        "type": "long",
        "index": false
      },
      "labelId":{
        "type": "long",
        "index": false
      },
      "html":{
        "type": "keyword",
        "index": false
      },
      "publicShow":{
        "type": "integer"
      },
      "addTimeShow":{
        "type": "keyword",
        "index": false
      },
      "author":{
        "type": "text",
        "analyzer": "text_anlyzer",
        "search_analyzer": "ik_smart"
      },
      "labelContent":{
        "type": "text",
        "analyzer": "text_anlyzer",
        "search_analyzer": "ik_smart"
      },
      "abstractText":{
        "type": "text",
        "analyzer": "text_anlyzer",
        "search_analyzer": "ik_smart"
      }
    }
  }
}


GET /langhaiblogs/_search
{
  "query": {
    "multi_match": {
      "query": "待更新",
      "fields": ["title", "author", "labelContent", "abstractText"]
    }
  }
}

GET /langhaiblogs/_search
{
  "query": {
    "match_all": {}
  }
}





有任何问题联系 QQ 676558206 email [email protected] [email protected]


延伸阅读
  1. 浪海博客系统友情链接说明
  2. 浪海同志的一生
  3. 浪海皇室 QQ飞车手游
  4. 浪海博客系统部署说明
  5. minio 相关说明
  6. mysql相关说明
  7. java基础面试题002
  8. rabbitMQ 相关说明
  9. gateway服务网关基本使用
  10. nacos配置中心基本使用
如果出现代码等内容显示不正常,使用以前的显示器:以前的显示器
发表评论