网站首页 > 精选文章 正文
1.创建es索引,使用分词
PUT test{
"settings":{ "number_of_shards":5,//分片 "number_of_replicas":1,//服务器台数 "analysis":{ "analyzer":{ "ik":{"tokenizer":"ik_max_word"}//设置分词解释器 } } }, "mappings":{ "properties":{ "name":{ "type":"text" }, "class":{ "type":"text" } } } }
2.插入数据
POST /test/_doc/1{
"name":"西红柿",
"class":"水果"
}
3.创建位置索引,根据
//地理位置
PUT /address{
"mappings": {
"properties": { "name": { "type": "text" }, "location": { "type": "geo_point" } } }}
4.插入地理位置坐标
POST /address/_doc/1
{
"name": "广州公园前",
"location": "23.131479, 113.270719"
}
5.根据各个位置地点的距离匹配精确度
GET / address / _search
{
"query": {
"bool": {
"filter": {
"geo_distance": {
"distance": "1km",
"location": {
"lat": 23.131304,
"lon": 113.262402
}
}
}
}
},
"sort": [ {
"_geo_distance": {
"unit": "km", "location": { "lat": 23.131304, "lon": 113.262402 }, "order": "asc" } } ]}
6.查看ik分词结果
GET _analyze{
"analyzer":"ik_max_word"
"text":"中华人民共和国"
}
7.批量插入数据代码来实现如php
//未指定id,使用es自动生成的id
for ($i = 0; $i < 5; $i++)
{
$params['body'][] = [
'index' => [
'_index' => 'testpeople',
'_type' => '_doc',
]
];
$params['body'][] = [
'age' => 17 + $i
];
}
//如果指定id的话
for ($i = 0; $i < 5; $i++)
{
$params['body'][] = [
'create' => [ #未指定id使用create创建
'_index' => 'my_index',
'_type' => '_doc',
'_id' => $i
]
];
$params['body'][] = [
'age' => 17 + $i
];
}
$ElasticSearch = new ElasticSearch();
$ElasticSearch->postBulkDoc($params);
7.删除操作
//批量删除
DELETE testpeople/_doc/delete_by_query
{
"query":{
"match_all":{}
}
}
//单个删除,根据id删除
DELETE testpeople/_doc/1
猜你喜欢
- 2024-12-10 这些好用的支持webdav的网盘和应用你知道吗?
- 2024-12-10 《DevSecOps左移指南》,你了解多少?
- 2024-12-10 服务器断电后启动报错:Generating /run/initramfs/rdso..txt
- 2024-12-10 门禁停车场管理系统无法通讯不能连接数据库的解决办法
- 2024-12-10 看完就明白/dev/sda、/dev/hda是什么了
- 最近发表
- 标签列表
-
- 向日葵无法连接服务器 (32)
- git.exe (33)
- vscode更新 (34)
- dev c (33)
- git ignore命令 (32)
- gitlab提交代码步骤 (37)
- java update (36)
- vue debug (34)
- vue blur (32)
- vscode导入vue项目 (33)
- vue chart (32)
- vue cms (32)
- 大雅数据库 (34)
- 技术迭代 (37)
- 同一局域网 (33)
- github拒绝连接 (33)
- vscode php插件 (32)
- vue注释快捷键 (32)
- linux ssr (33)
- 微端服务器 (35)
- 导航猫 (32)
- 获取当前时间年月日 (33)
- stp软件 (33)
- http下载文件 (33)
- linux bt下载 (33)