ELASTIC-PHP + IK分词器 + THINKPHP6 初次使用 (关键词查询)

本文档详细介绍了在CentOS6环境下,如何安装Elasticsearch 7.7.1并配置为非root用户运行,同时通过华为云镜像加速下载。接着,介绍了如何添加ik分词插件以支持中文搜索。在PHP部分,通过composer引入elasticsearch-php库,并展示了创建索引、添加、删除、更新和查询文档的代码示例,适用于PHP7.3。最后,给出了实际案例的链接。

环境:centos 6 php73 mysql56  ELASTIC7.71

1.安装elastic  使用华为云镜像更快哦 https://mirrors.huaweicloud.com/elasticsearch/

wget https://mirrors.huaweicloud.com/elasticsearch/7.7.1/elasticsearch-7.7.1-linux-x86_64.tar.gz

tar -zxvf elasticsearch-7.7.1-linux-x86_64.tar.gz 

2.添加用户(用户启动elastic 不能用root所以) 去目录里面编辑配置 elastic.yml

groupadd elastic
useradd -g elastic elastic
chown -R elastic.elastic /etc/elasticsearch-7.7.1
vim config/elasticsearch.yml 

  配置如下 注意冒号后有空格

------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: hxx-node-1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
path.data: /var/elastic/data
#
# Path to log files:
#
path.logs: /var/elastic/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 127.0.0.1
#
# Set a custom port for HTTP:
#
http.port: 9200
#
# For more information, consult the network module documentation.
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 127.0.0.1
#
# Set a custom port for HTTP:
#
http.port: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.seed_hosts: ["host1", "host2"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
cluster.initial_master_nodes: ["hxx-node-1"]

cluster.routing.allocation.disk.watermark.flood_stage: 99%
cluster.routing.allocation.disk.threshold_enabled: false

  3.安装ik分词库(用于中文)  下载对应的哦 7.7.1

https://github.com/medcl/elasticsearch-analysis-ik/releases

不管你用何种方法  放到安装路径里  /etc/elasticsearch-7.7.1/plugins/ik

好了 切换到 elastic 然后运行elastic

su elastic
./bin/elastic -d

 可进行测试

[root@iZuf64idor3ej85kby45arZ elasticsearch-7.7.1]# curl 127.0.0.1:9200
{
  "name" : "hxx-node-1",
  "cluster_name" : "hxx",
  "cluster_uuid" : "-43vGhX0Ru2ocVqNO7VhyA",
  "version" : {
    "number" : "7.7.1",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "ad56dce891c901a492bb1ee393f12dfff473a423",
    "build_date" : "2020-05-28T16:30:01.040088Z",
    "build_snapshot" : false,
    "lucene_version" : "8.5.1",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"

  二、PHP部分

1.composer 引入 elastic-php(使用phpstorm更方便)
 

"elasticsearch/elasticsearch": "~7.0",<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值