创建索引、指定映射
PUT /toutiao_v1
{
"mappings": {
"properties": {
"author": {
"type": "keyword"
},
"content": {
"type": "text"
},
"date": {
"type": "date"
},
"like": {
"type": "integer"
},
"type": {
"type": "keyword"
},
"title": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
可通过 title.keyword 字段实现关键词搜索及数据聚合
添加文档
POST /toutiao_v1/_doc
{
"title": "JAVA技巧",
"content": "JAVA高级技巧",
"author":"李雷",
"like":229,
"date":"2021-08-30",
"type":"java"
}
POST /toutiao_v1/_doc
{
"title": "JAVA mysql技巧大全",
"content": "JAVA mysql技巧大全",
"author":"李雷",
"like":528,
"date":"2021-08-29",
"type":"java"
}
POST /toutiao_v1/_doc
{
"title": "JAVA从入门到放弃",
"content": "JAVA高手的技巧,java基础、高级",
"author":"韩梅梅",
"like":983,
"date":"2021-08-29",
"type":"java"
}
POST /toutiao_v1/_doc
{
"title": "mysql从入门到放弃",
"content": "mysql技术内幕",
"author":"李四",
"like":397,
"date":"2021-08-29",
"type":"mysql"
}
POST /toutiao_v1/_doc
{
"title": "elasticsearch技术大全",
"content": "java操作elasticsearch",
"author":"lucy",
"like":191,
"date":"2022-03-29",
"type":"elasticsearch"
}
POST /toutiao_v1/_doc
{
"title": "java常用工具类",
"content": "常用工具类和常用代码",
"author":"lili",
"like":231,
"date":"2022-03-28",
"type":"java"
}