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的博客-CSDN博客_es mapping type