0
点赞
收藏
分享

微信扫一扫

2022-02-22 Elasticsearch 7.12.1 安装


  1. 分别安装elasticsearch elasticsearch-head
  2. linxu安装elasticsearch
  3. 访问elasticSearch官网地址 https://www.elastic.co/
  4. 选择7.12.1下载,上传到服务器
  5. tar -zxvf elasticsearch-*******
  6. 进入到config文件夹中,修改elasticsearch.yml

<pre data-language="xml" id="vaB3w" class="ne-codeblock language-xml" style="border: 1px solid #e8e8e8; border-radius: 2px; background: #f9f9f9; padding: 16px; font-size: 13px; color: #595959">node.name: node-1

开启跨域访问支持,默认为false

http.cors.enabled: true

# 跨域访问允许的域名地址

http.cors.allow-origin: "*"

# 通过为 cluster.initial_master_nodes 参数设置符合主节点条件的节点的 IP 地址来引导启动集群

cluster.initial_master_nodes: ["node-1"]
network.host: 0.0.0.0</pre>

  1. 此操作都是root用户,现在需要创建一个普通用户例如mix_usr
  2. useradd mix_usr
  3. passwd 123
  4. 再输入两次密码(自定义)
  5. chown -R testuser:testuser /usr/local/elasticsearch 更改文件分组, /usr/local/自己的elasticsearch 解压路径
  6. vi /etc/security/limits.conf 添加如下内容

<pre data-language="xml" id="rQIiM" class="ne-codeblock language-xml" style="border: 1px solid #e8e8e8; border-radius: 2px; background: #f9f9f9; padding: 16px; font-size: 13px; color: #595959"># 在root用户下追加配置
vim /etc/security/limits.conf

配置内容 *表示所有用户生效

  • soft nofile 65536
  • hard nofile 65536

重新登录即可生效

可使用命令查看是否生效

ulimit -H -n</pre>

  1. 进入elasticsearch的bin目录 运行启动命令 ./elasticsearch 或者 后台启动命令 ./elasticsearch -d
  2. 浏览器访问ip:9200
  3. 出现json内容证明安装完毕

<pre data-language="json" id="X4Ky4" class="ne-codeblock language-json" style="border: 1px solid #e8e8e8; border-radius: 2px; background: #f9f9f9; padding: 16px; font-size: 13px; color: #595959">{
 name: "node-1",
 cluster_name: "elasticsearch",
 cluster_uuid: "RvqWGNf2TEe5RqnxPKOQwA",
 version: {
 number: "7.12.1",
 build_flavor: "default",
 build_type: "tar",
 build_hash: "3186837139b9c6b6d23c3200870651f10d3343b7",
 build_date: "2021-04-20T20:56:39.040728659Z",
 build_snapshot: false,
 lucene_version: "8.8.0",
 minimum_wire_compatibility_version: "6.8.0",
 minimum_index_compatibility_version: "6.0.0-beta1"
 },
 tagline: "You Know, for Search"
 }</pre>

  1. 安装elasticsearch-head插件,需要nodejs等 用到的npm

<pre data-language="json" id="ibjfl" class="ne-codeblock language-json" style="border: 1px solid #e8e8e8; border-radius: 2px; background: #f9f9f9; padding: 16px; font-size: 13px; color: #595959">yum install –y git
 git clone git://github.com/mobz/elasticsearch-head.git cd elasticsearch-head
 npm install -g grunt-cli
 npm install -g grunt
 npm install grunt-contrib-copy
 npm install grunt-contrib-concat
 npm install grunt-contrib-uglify
 npm install grunt-css
 npm install
 npm run start启动或者后台启动 nohup npm run start &</pre>

  1. 安装完成后需要重新启动elasticsearch
  2. 浏览器访问ip:9100,可以看到插件界面.红色处注意改成自己的ip地址,默认为localhost


  3. 2022-02-22 Elasticsearch 7.12.1 安装_python

  4. image
  5. 分词器安装 进入到/bin文件夹下执行命令

<pre data-language="json" id="hJ45h" class="ne-codeblock language-json" style="border: 1px solid #e8e8e8; border-radius: 2px; background: #f9f9f9; padding: 16px; font-size: 13px; color: #595959">/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.12.1/elasticsearch-analysis-ik-7.12.1.zip</pre>

安装分词器的作用,在于搜索的时候,例如搜索: "中国人",那么有分词器就会去全文检索中找"中国"或者"人"的两个词,如果没有分词器,那么只会找"中国人" 这个词

  1. 安装完成后需要重启elasticsearch
  2. 查看进程 ps -ef|grep elasticsearch
  3. kill -9 端口号 杀死进程
  4. 执行启动命令 ./elasticsearch
  5. 具体代码demo在 项目test中
  6. 测试类 ElasticSearchTest
  7. 具体实际使用需要elasticsearch的初始化配置,具体配置在 ElasticSearchConfig 示例代码在 ElasticsearchImpl
  8. 官网dsl语句参考地址: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html#query-dsl
  9. 倒排索引,正向索引就是,在每个文档中,文档id与 关键词出现的次数以及位置列表的对应关系
  10. 倒排索引则是 转换了另一种格式,变为 关键词与文档id的对应关系

  11. 2022-02-22 Elasticsearch 7.12.1 安装_es_02

  12. image
  13. 这就是一个正向索引,搜索词汇1和词汇4
  14. 结果为 文档1 : 2 次 集合为: 0,3;文档4 : 1 次 集合为: 0 ;文档5 : 1 次 集合为: 3
  15. 倒排索引后变为, 词汇1: 文档1的id,文档4的id; 词汇4: 文档1的id,文档5的id
  16. elasticsearch查询,都要进行倒排索引
  17. 全文检索: 利用分词器进行分词,然后查询 match(单字段查询)/multi_match(多字段查询)
  18. 精确查询: 例如keyword,数值,日期,boolean类型,无需分词,进行查询; ids range区间 trem数值
  19. 地理查询: geo,经纬度查询; geo_distance/ geo_bounding_box
  20. 复合查询: 将上述条件组合起来查询 bool 与或非
  21. 搜索示例
  22. https://docs.apipost.cn/preview/7511b95fdadb1c1b/ff229a63eae3b80a -- 按照title分词检索
  23. https://docs.apipost.cn/preview/0970d532cc8e1208/23708e60e7b12539 --无条件的搜索
  24. 搜索的时候,越是匹配度高的,越靠前
举报

相关推荐

0 条评论