- 安装ES 7.X版本
- 安装ik分词(注意与ES版本一致)
本文针对 ES7.8版本执行完成
# 启动
systemctl start elasticsearch.service
# 停止
systemctl stop elasticsearch.service
# 设置系统自动启动
systemctl enable elasticsearch.service
PUT http://ip:9200/users/_doc/?pretty
{
"mappings": {
"properties": {
"user_name": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_smart"
},
"user_phone": {
"type": "keyword",
"analyzer": "ik_max_word",
"search_analyzer": "ik_smart"
},
"user_age": {
"type": "integer"
},
"user_remark": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_smart"
},
"create_time": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
}
}
}
}
POST http://ip:9200/users/_doc/?pretty
{
"user_name":"XXXXX",
"user_phone": "186XXXXXXXX",
"user_age": 30,
"user_remark": "这里省略一万字",
"create_time": "2020-12-07 12:59:59"
}
GET http://10.10.151.52:9200/users/_search
{
"from": 0,
"size": 10,
"query": {
"match": {
"user_name": "李"
}
},
"highlight": {
"pre_tags": [
"<tag1>"
],
"post_tags": [
"</tag1>"
],
"fields": {
"user_name": {}
}
}
}
GET http://10.10.151.52:9200/users/_search
{
"query": {
"terms": {
"user_name.keyword": "李xxxx"
}
}
}
GET http://ip:9200/_analyze?pretty
{
"analyzer": "ik_smart",
"text": "一万个字"
}
DELETE http://ip:9200/users
{
"sort": [
{
"create_time.keyword": "desc"
}
],
"query": {
"bool": {
"filter": {
"range": {
"create_time.keyword": {
"gte": "2020-01-01",
"lte": "2020-12-31",
"format": "yyyy-MM-dd"
}
}
},
"must": {
"bool": {
"should": [
{
"term": {
"user_name.keyword": "汇川技术"
}
},
{
"term": {
"user_name.keyword": "长城汽车"
}
}
]
}
},
"should": [
{
"match": {
"user_remark": "2020年汇川技术和长城汽车所有事件"
}
}
]
}
}
}