基础操作
#按照liveatdId字段检索
{
"query":{
"bool":{
"must":{
"match":{
"liveatdId":"LIVEATD20220505000000000001"
}
}
}
}
}
#条件匹配
GET /index_name/_search
{
"query":{
"match":{
"name":"zhangsan"
}
},
"sort":[
{
"age":"desc"
}
]
}
#分页查询
#分页查找
GET ses_liveatd_monitor_2023_1/_search
{
"from" : 0, "size" : 1000,
"query" : {
"term" : { "channelId" : "3796202" }
}
}
#范围查询
GET /index_name/_search
{
"query":{
"bool":{
"must":{
"match":{
"name":"zhangsan"
}
},
"filter":{
"range":{
"age":{"gt":25}
}
}
}
},
"sort":[
{
"age":"desc"
}
]
}
#highlight search(高亮搜索)
GET /index/type/_search
{
"query":{
"match_phrase":{
"name":"zhangsan"
}
} ,
"highlight":{
"fields":{
"name":{}
}
}
}
#查找mapping结构
GET index_name/_mapping?pretty
#查找index数据
GET index_name/_search
#删除index
DELETE index_name
#创建mapping结构,验证版本:6.8.0
PUT index_temp
{
"mappings":{
"_doc":{
"properties":{
"channelId":{
"type":"keyword"
},
"createdDate":{
"type":"date",
"format":"yyyy-MM-dd HH:mm:ss"
},
"liveatdId":{
"type":"keyword"
},
"liveatdlistMonitorId":{
"type":"keyword"
},
"modifiedDate":{
"type":"date",
"format":"yyyy-MM-dd HH:mm:ss"
},
"monitorImageUrl":{
"type":"text"
},
"monitorTime":{
"type":"date",
"format":"yyyy-MM-dd HH:mm:ss"
},
"round":{
"type":"keyword"
},
"scheduleId":{
"type":"keyword"
},
"userId":{
"type":"keyword"
}
}
}
}
}
#增加字段
PUT index_name/_mapping/_doc
{
"properties":{
"sku_extendInfo":{
"type":"text"
},
"sku_stock":{
"type":"integer"
}
}
}
#别名操作
POST /_aliases
{
"actions": [
#移除别名
{ "remove": { "index": "index_name_old", "alias": "index_name_alias" }},
#新增别名
{ "add": { "index": "index_name_new", "alias": "index_name_alias" }}
]
}
#新增ES数据
POST /index_name/_doc
{
"liveatdlistMonitorId" : "LISTMONITOR20230307000000000016",
"liveatdId" : "LIVEATD20230301010000000004",
"userId" : "USER20190417010000316584",
"scheduleId" : "SCHEDULE20230301000000004983",
"channelId" : "3793552",
"round" : null,
"monitorImageUrl" : "2023/03/07/A/1678187358831040000030449.jpg",
"monitorTime" : "2023-03-07 19:09:18",
"createdDate" : "2023-03-07 18:43:46",
"modifiedDate" : "2023-03-07 19:09:18"
}
#根据条件删除索引数据
POST index_name/_delete_by_query
{
"query": {
"match": {
"businessSourceId": "DETAIL20230401000000000001"
}
}
}
#将old_index数据复制到new_index,前提:两个index必须都存在,类型不同时也可以使用,如果新的结构不存在的字段会被新增
POST _reindex
{
"source": {
"index": "old_index"
},
"dest": {
"index": "new_index"
}
}