docker安装es
mkdir -p /usr/local/esdata/config
mkdir -p /usr/local/esdata/data
mkdir -p /usr/local/esdata/plugins
vi /usr/local/esdata/config/elasticsearch.yml
#文本输入如下
http.host: 0.0.0.0
启动命令
docker run --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms64m -Xmx128m" -v /usr/local/esdata/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /usr/local/esdata/data:/usr/share/es/data -v /usr/local/esdata/plugins:/usr/share/elasticsearch/plugins -d elasticsearch:7.6.2
安装分词器插件
1、use elasticsearch-plugin to install
docker exec -it elasticsearch /bin/sh
cd bin/
elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.1.1/elasticsearch-analysis-ik-7.1.1.zip
#执行完毕后
elasticsearch-plugin list #查看
elasticsearch-plugin remove analysis-ik #删除
2、download 插件
docker exec -it elasticsearch /bin/sh
cd plugins && mkdir ik
wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.1.1/elasticsearch-analysis-ik-7.1.1.zip
unzip elasticsearch-analysis-ik-7.1.1.zip
======安装完成后重启服务======
====增加分词====
docker exec -it elasticsearch /bin/sh
cd config/analysis-ik/
echo '济南彭于晏' >> main.dic
======安装完成后重启服务======
http://*****:9200/_cat/indices?v&pretty
查询所有的索引
http://****:9200/my_index?pretty
my_index 是索引名称 查询该索引的定义
GET my_index/_search
{
"query":{
"match_all":{
}
}
}
查询当前索引的内容【my_index 代表索引名称】
数字类型
对于数字类型,ELasticsearch支持以下几种:
类型 取值范围
long -2^63至2^63-1
integer -2^31至2^31-1
short -32,768至32768
byte -128至127
double 64位双精度IEEE 754浮点类型
float 32位单精度IEEE 754浮点类型
half_float 16位半精度IEEE 754浮点类型
scaled_float 缩放类型的的浮点数(比如价格只需要精确到分,price为57.34的字段缩放因子为100,存起来就是5734)
对于float、half_float和scaled_float,-0.0和+0.0是不同的值,使用term查询查找-0.0不会匹配+0.0,同样range查询中上边界是-0.0不会匹配+0.0,下边界是+0.0不会匹配-0.0。
对于数字类型的数据,选择以上数据类型的注意事项:
在满足需求的情况下,尽可能选择范围小的数据类型。字段的长度越短,索引和搜索的效率越高。
优先考虑使用带缩放因子的浮点类型。
PUT my_index
{
"mappings": {
"my_type": {
"properties": {
"number_of_bytes": {
"type": "integer"
},
"time_in_seconds": {
"type": "float"
},
"price": {
"type": "scaled_float",
"scaling_factor": 100
}
}
}
}
}
插入一条记录 或者根据文档ID进行更新
PUT my_index/_doc/1
{
"number_of_bytes": "1",
"time_in_seconds": "1.44",
"price": "13.3225"
}
禁止未定义类型的字段插入es【 "dynamic": "strict"】 写入的时候报错
PUT my_index
{
"mappings": {
"dynamic": "strict",
"properties": {
"title": {
"type": "text"
},
"price": {
"type": "scaled_float",
"scaling_factor": 100
}
}
}
}
关闭索引【查询、插入时候报错索引已关闭】
POST my_index/_close
开启索引
POST my_index/_open
日期类型
PUT my_index/my_type/1
{ "date": "2015-01-01" }
PUT my_index/my_type/2
{ "date": "2015-01-01T12:10:30Z" }
PUT my_index/my_type/3
{ "date": 1420070400001 }
GET my_index/_search
{
"sort": { "date": "asc"}
}
数组类型
ELasticsearch没有专用的数组类型,默认情况下任何字段都可以包含一个或者多个值,但是一个数组中的值要是同一种类型。例如:
字符数组: [ “one”, “two” ]
整型数组:[1,3]
嵌套数组:[1,[2,3]],等价于[1,2,3]
对象数组:[ { “name”: “Mary”, “age”: 12 }, { “name”: “John”, “age”: 10 }]
注意事项:
动态添加数据时,数组的第一个值的类型决定整个数组的类型
混合数组类型是不支持的,比如:[1,”abc”]
数组可以包含null值,空数组[ ]会被当做missing field对待。
PUT my_index/_doc/1
{
"title": ["US is a bad title","dasdas"],
"price": "15.3225",
"date":"2022-06-25T12:00:00"
}
ES Mapping、字段类型Field type详解_ZhaoYingChao88的博客-优快云博客_es mapping type
分词器tokenizer 种类
https://jingyan.baidu.com/article/cbcede071e1b9e02f40b4d19.html
filter
常用的过滤器
本文介绍了如何在Docker中安装Elasticsearch,包括配置文件设置、单节点启动,以及分词器插件的安装、管理与索引操作,如添加分词、查询和数据类型选择。
1427

被折叠的 条评论
为什么被折叠?



