概要
结构化搜索针对日期、时间、数字等结构化数据的搜索,它们有自己的格式,我们可以对它们进行范围,比较大小等逻辑操作,这些逻辑操作得到的结果非黑即白,要么符合条件在结果集里,要么不符合条件在结果集之外,没有那种相似的概念。
前言
结构化搜索将会有大量的搜索实例,我们将"音乐APP"作为主要的案例背景,去开发一些跟音乐APP相关的搜索或数据分析,有助力于我们理解实战的目标,顺带巩固一下学习的知识。
我们将一首歌需要的字段暂定为:
name |
code | type | remark |
---|---|---|---|
ID | id | keyword | 文档ID |
歌手 | author | text | |
歌曲名称 | name | text | |
歌词 | content | text | |
语种 | language | text | |
标签 | tags | text | |
歌曲时长 | length | long | 记录秒数 |
喜欢次数 | likes | long | 点击喜欢1次,自增1 |
是否发布 | isRelease | boolean | true已发布,false未发布 |
发布日期 | releaseDate | date |
我们手动定义的索引mapping信息如下:
PUT /music
{
"mappings": {
"children": {
"properties": {
"id": {
"type": "keyword"
},
"author_first_name": {
"type": "text",
"analyzer": "english"
},
"author_last_name": {
"type": "text",
"analyzer": "english"
},
"author": {
"type": "text",
"analyzer": "english",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"content": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"language": {
"type": "text",
"analyzer": "english",
"fielddata": true
},
"tags": {