本文共 2506 字,大约阅读时间需要 8 分钟。
列出所有索引(列出所有的数据库)GET /_cat/indices?v
PUT /goods{ "settings": { // 副本数 "number_of_replicas": 1, // 分片数 "number_of_shards": 5 }}
DELETE /goods
POST /goods/_doc/1/_update{ "doc": { "price":100 }}
GET /goods/_search// 查询是xiaomi9的GET /goods/_search{ "query": { "match": { "title": "xiaomi9" } }}// 排序GET /goods/_search{ "query": { "match_all": { } }, "sort": [ { "_id": { "order": "desc" } } ]}## 进行中文分词搜索PUT /goods{ "mappings": { "_doc":{ "properties":{ "name":{ "type":"text", "analyzer":"ik_max_word", "search_analyzer":"ik_max_word" }, "desn":{ "type":"text", "analyzer":"ik_max_word", "search_analyzer":"ik_max_word" } } } }}
官网:
$hosts = [ '127.0.0.1:9200'];$client = \Elasticsearch\ClientBuilder::create()->setHosts($hosts)->build();// 创建索引 number_of_shards 分区数后期不可更改 number_of_replicas 副本数后期可更改$params = [ 'index' => 'goods', 'body' => [ 'settings' => [ 'number_of_shards' => 5, 'number_of_replicas' => 1 ], 'mappings' => [ '_doc' => [ '_source' => [ 'enabled' => true ], 'properties' => [ 'title' => [ 'type' => 'keyword' ], 'desn' => [ 'type' => 'text', 'analyzer' => 'ik_max_word', 'search_analyzer' => 'ik_max_word' ] ] ] ] ]];$response = $client->indices()->create($params);
$hosts = [ '127.0.0.1:9200',];$client = \Elasticsearch\ClientBuilder::create()->setHosts($hosts)->build();// 写文档$params = [ 'index' => 'goods', 'type' => '_doc', 'id' => $model->id, 'body' => [ 'title' => $model->title, 'desn' => $model->desn, ],];$response = $client->index($params);
$hosts = [ '127.0.0.1:9200',];$client = \Elasticsearch\ClientBuilder::create()->setHosts($hosts)->build();$params = [ 'index' => 'goods', 'type' => '_doc', 'body' => [ 'query' => [ 'match' => [ 'title'=>[ 'query' => '手机' ] ] ] ]];$results = $client->search($params);dump($results);
转载地址:http://priws.baihongyu.com/