1、安装遇到的坑
安装ES:
- 需要在配置关闭ssl验证
- 安装过程中有打印密码等信息,可以复制,也可以用elasticsearch-reset-password.bat重置密码
安装kibana:
- 需要配置es地址
- 提示没有登陆,配置了账号密码,然后提示不能用elastic账号,可以用token,用elasticsearch-service-tokens.bat获取了token,配置后启动成功(获取账号时需要是elastic/kibana命名空间的 不能是elastic/fleet-server的)
2、简介
3、简单使用
//链接
$e = \Elasticsearch\ClientBuilder::create()
->setBasicAuthentication('elastic', '密码') //用户名密码
//->setApiKey() //api登录(用户名2选1)
->setHosts(['127.0.0.1:9200']) //改端口
->build();
//版本信息
$elastic = $e->info();
//索引存在
$e->indices()->exists(['index' => 'k']);
//创建简单索引
$e->indices()->create(['index' => 'k']);
//获取索引映射
$e->indices()->getMapping(['index' => 'k']);
//更新索引影射
$client->update($params);
//增
$e->index(['index' => 'k', 'body' => ['dd' => date('Y-m-d H:i:s')]])
//ID单查
$e->get(['index' => 'k', 'id' => 'PbudUYEBuG61Ky6oi7Pk'])
//模糊查询
$params = [
'index' => 'k',
'body' => [
'query' => [
'match' => [
'dd' => '2022'
]
]
]
];
$e->search($params);
//改
$params = [
'index' => 'k',
'id' => 'P7vCUYEBuG61Ky6otrO5',
'body' => [
'doc' => [
'dd' => '2022'
]
]
];
$e->update($params);
//删
$e->deleteByQuery($params);
//删除索引
$e->indices()->delete(['index' => 'k']);
4、坑
//precision_threshold:接受 0–40000 之间的数字,更大的值还是会被当作 40000 来处理。
GET /myindex/mytype/_search
{
"size" : 0,
"aggs" : {
"distinct_idCard" : {
"cardinality" : {
"field" : "idCard",
"precision_threshold" : 100
}
}
}
}
5、kibana的dev tools使用
//SQL查询
POST /_sql?format=txt
{
"query" :"SELECT DISTINCT createDate FROM index"
}
//查询ES语法
POST /_sql/translate
{
"query": "SELECT count(DISTINCT amazonOrderId) from es_index_order_item_list_ori where purchaseDate>=1654012800 AND purchaseDate<1654099200 AND showName = 'BPQE-US' AND orderStatus IN ('Pending', 'Unshipped', 'Shipped')"
}
//删除索引
DELETE /es_index_am_sales_seller_sku