7.x版本对比5.x版本,移除的type字段,默认使用_doc type类型
常用api
#创建索引和mapping
PUT datacenter_laws
{
"settings": {
"number_of_shards": 3,
"index.refresh_interval": "5s"
},
"mappings": {
"properties": {
"id": {
"type": "keyword",
"ignore_above": 256
},
"pick_url": {
"type": "keyword",
"ignore_above": 256
},
"content_html": {
"type": "text"
},
"content_text": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_smart",
"fields": {
"suggest": {
"type": "completion"
}
}
},
"effective_date": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
},
"effectiveness": {
"type": "keyword",
"ignore_above": 256
},
"issue_authority": {
"type": "keyword",
"ignore_above": 256
},
"pick_date": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
},
"issue_date": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
},
"issue_no": {
"type": "keyword",
"ignore_above": 256
},
"site_name": {
"type": "keyword",
"ignore_above": 256
},
"title": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
},
"suggest": {
"type": "completion"
}
},
"analyzer": "ik_max_word",
"search_analyzer": "ik_smart"
},
"type1": {
"type": "keyword",
"ignore_above": 256
},
"type2": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
#scroll深度分页查询,不支持跳页,跳页用最简单的from,size
GET datacenter_laws/_search
{
"size": 1,
"query": {
"multi_match": {
"query": "学习",
"fields": ["title","content_text"]
}
},
"sort": [
{
"issue_date": {
"order": "asc"
},
"id": {
"order": "desc"
}
}
]
}
#获取到search_after需要的值,然后分页查询
GET datacenter_laws/_search
{
"size": 1,
"query": {
"multi_match": {
"query": "学习",
"fields": ["title","content_text"]
}
},
"sort": [
{
"issue_date": {
"order": "asc"
},
"id": {
"order": "desc"
}
}
],
"search_after": [
1625992020000,
"37f9a47944c10ea6ede98c9e7d92cb43"
]
}
#删除索引
DELETE datacenter_laws
#删除指定id索引
DELETE datacenter_laws/_doc/uRW4U3sBTAVER0k-Kpav
#多id删除
POST oa_material_document/_delete_by_query
{
"query": {
"terms": {
"FIELD": [
"VALUE1",
"VALUE2"
]
}
}
}
#查询
GET datacenter_laws/_search
#查询mapping
GET datacenter_laws/_mapping
#搜索建议自动完成
POST datacenter_laws/_search
{
"suggest": {
"my-suggest": {
"text": "学",
"completion": {
"field": "title.suggest"
}
}
}
}
#多值匹配
GET datacenter_laws/_search
{
"query": {
"terms": {
"FIELD": [
"VALUE1",
"VALUE2"
]
}
}
}
#多字段匹配
GET datacenter_laws/_search
{
"query": {
"multi_match": {
"query": "扶贫",
"fields": ["title","content_text"]
}
},
"from": 0,
"size": 20
}
ElasticSearch7.6无感知修改Mapping属性
PUT datacenter_laws_v2
{
"settings": {
"number_of_shards": 3,
"index.refresh_interval": "5s"
},
"mappings": {
"properties": {
"id": {
"type": "keyword",
"ignore_above": 256
},
"pick_url": {
"type": "keyword",
"ignore_above": 256
},
"content_html": {
"type": "text"
},
"content_text": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_smart",
"fields": {
"suggest": {
"type": "completion"
}
}
},
"effective_date": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
},
"effectiveness": {
"type": "keyword",
"ignore_above": 256
},
"issue_authority": {
"type": "text"
},
"pick_date": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
},
"issue_date": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
},
"issue_no": {
"type": "keyword",
"ignore_above": 256
},
"site_name": {
"type": "keyword",
"ignore_above": 256
},
"title": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
},
"suggest": {
"type": "completion"
}
},
"analyzer": "ik_max_word",
"search_analyzer": "ik_smart"
},
"type_first": {
"type": "keyword",
"ignore_above": 256
},
"type_second": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
POST _reindex
{
"source": {
"index": "datacenter_laws_v1"
},
"dest": {
"index": "datacenter_laws_v2"
}
}
如果数据量量较大,报错是正常的,但是后台会需求复制数据
POST /_aliases
{
"actions": [
{ "remove": { "index": "datacenter_laws_v1", "alias": "datacenter_laws" }},
{ "add": { "index": "datacenter_laws_v2", "alias": "datacenter_laws" }}
]
}
|