Elastic 建表查询 curl

一, 创建表

curl 方式建表需要先建立索引, 然后创建表头. 删表的时候删除索引即可.

创建索引

  1. 创建 user 表索引, pretty 参数能让输出美化一点

curl -XPUT http://localhost:9200/user?pretty

索引创建成功后返回:

删除索引

删除索引同时会自动删除内容

查看索引

默认列出所有索引
curl -XGET 'localhost:9200/_cat/indices?v&pretty'

创建表头

创建索引之后建立表头, 至此数据表建立成功

查看表头

插入/修改数据

$arr = ['id' => 120, 'name' => '陈临政', 'title' => '老板', 'zhiwei' => '大老板', 'wxname' => '快乐的猪'];
app('es')->index(['id' => 1, 'index' => 'fp_user', 'type' => '_doc', 'body' => $arr]);

app(‘es’)->get([‘index’ => ‘fp_user’, ‘type’ => ‘_doc’, ‘id’ => 6])

app(‘es’)->get([‘index’ => ‘post’, ‘type’ => ‘_doc’, ‘id’ => 6])

二, 查询表

bool 查询

分页查询

排序查询

联合查询

“`sh
params = [ ‘index’ => ‘fp_user’, ‘type’ => ‘_doc’, ‘body’ => [ ‘query’ => [ ‘bool’ => [ ‘should’ => [ [‘term’ => [‘zhiwei’ => ‘cpo’]], [‘term’ => [‘title’ => ‘financier’]], ], ], ], ], ]; results = app(‘es’)->search(params); params = [
‘index’ => ‘post’,
‘type’ => ‘_doc’,
‘body’ => [
‘query’ => [
‘bool’ => [
‘should’ => [
[‘term’ => [‘user’ => $results] ],
],
],
],
],
]

Hello world!
文章已创建 211

相关文章

开始在上面输入您的搜索词,然后按回车进行搜索。按ESC取消。

返回顶部