PUT /test1/type1/1
{
"name":"bobwang",
"age":22
}
字段类型:
字符串类型:text, keyword
数值类型:long, integer,short,byte, double,float,half,scaled, float
布尔类型:boolean
二进制类型:binary
…
eg:
指定索引index的字段类型
PUT /test2
{
"mappings": {
"properties": {
"name":{
"type": "text"
},
"age":{
"type":"long"
},
"brithday":{
"type": "date"
},
"marrued":{
"type":"boolean"
}
}
}
}
#out
{
"acknowledged" : true,
"shards_acknowledged" : true,
"index" : "test2"
}
get 查看
GET /test2
# out
{
"test2" : {
"aliases" : { },
"mappings" : {
"properties" : {
"age" : {
"type" : "long"
},
"brithday" : {
"type" : "date"
},
"marrued" : {
"type" : "boolean"
},
"name" : {
"type" : "text"
}
}
},
"settings" : {
"index" : {
"creation_date" : "1592119203342",
"number_of_shards" : "1",
"number_of_replicas" : "1",
"uuid" : "k5pMbsUdSTa8RRzXPrXHpw",
"version" : {
"created" : "7060199"
},
"provided_name" : "test2"
}
}
}
}
如果字段没有指定, es会自己默认配置字段类型
通过get _cat/查看es的当前信息
GET _cat/indices?v
PUT /test2/_doc/1
{
"name":"wang",
"age":23,
"brithday":"2000-01-01",
"married":"false"
}
POST /test2/_doc/1/_update
{
"doc":{
"name":"bobwang"
}
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-0wBtOkd9-1592449903565)(/Users/bobwang/Library/Application Support/typora-user-images/image-20200614155902035.png)]
delete
DELETE test2
PUT /bob/user/1
{
"name":"bobwang",
"age":22,
"marreid":false
}
out
pplication Support/typora-user-images/image-20200614160947296.png)]
GET /bob/user/1
PUT /bob/user/1
{
"name":"bobwang",
"age":27,
"marreid":false
}
POST /bob/user/1/_update
{
"doc":{
"marreid":true
}
}
# 将 索引bob下在user文档(相当于mysql的表table)下的所有消息找出
GET bob/user/_search
# 查询条件是name=bobwang
GET bob/user/_search?q=name:bobwang
分数表示:如过匹配出多个结果,如果结果的匹配度越高,分值就越高
hits:包含了索引和文档的信息,查询的结果总数,当里面包含多条时,可以遍历出来。
GET bob/user/_search
{
"query":{
"match":{
"name": "bobwang"
}
}
}
# 匹配的条件采用 json格式
GET bob/user/_search
{
"query":{
"match":{
"name": "bobwang"
}
},
"_source":["age","marreid"]
}
GET bob/user/_search
{
"query":{
"match":{
"name": "bob"
}
},
"sort": [
{
"age": {
"order": "asc"
}
}
]
}
1、must(and):所有的条件都要符合
3、must_not(not)
5、过滤器 filter
多条件
6、匹配多个
term查询时直接通过倒排索引指定的词条进行精确查找的
match
两个类型:
standard
keyword
10、高亮查询
自定义高亮显示格式
DELETE bob/user/1
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-bdVEqkVp-1592449903587)(/Users/bobwang/Library/Application Support/typora-user-images/image-20200614185150354.png)]