限时 5折! 详情

hyperf 实战之 elasticsearch 全文检索

898 0 0

接上文,今天我们看下 elasticsearch 搜索部分的功能实现。

我们先安装下 elasticsearch 服务。

docker pull elasticsearch:7.17.5
cd ~/data/docker/env
mkdir -p elasticsearch/config
mkdir -p elasticsearch/data
echo "http.host: 0.0.0.0" > elasticsearch/config/elasticsearch.yml
chmod -R 777 elasticsearch

创建容器

docker run --name elasticsearch -p 9200:9200 -p 9300:9300  --restart=always -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms64m -Xmx512m" 
-v ~/data/docker/env/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml 
-v ~/data/docker/env/elasticsearch/data:/usr/share/elasticsearch/data 
-v ~/data/docker/env/elasticsearch/plugins:/usr/share/elasticsearch/plugins 
-d elasticsearch:7.17.5

elasticsearch 安装好之后,简单测试一下

➜  ~  curl http://127.0.0.1:9200/question/_search
{"error":{"root_cause":[{"type":"index_not_found_exception","reason":"no such index [question]","resource.type":"index_or_alias","resource.id":"question","index_uuid":"_na_","index":"question"}],"type":"index_not_found_exception","reason":"no such index [question]","resource.type":"index_or_alias","resource.id":"question","index_uuid":"_na_","index":"question"},"status":404}%

很显然我们还没有一个叫“question”的索引,到这一步就说明 es 安装是成功的。

hyperf 安装 es 组件并配置

Hyperf/Scout 为模型的全文搜

去购买

还有90%的精彩内容,购买继续阅读