PUT /books
{
"settings": {
"number_of_shards": 5,
"number_of_replicas": 1,
"index": {
"analysis.analyzer.default.type" : "ik_max_word"
}
},
"mappings": {
"properties": {
"title": {
"type": "text",
"fields": {
"keyword":{
"ignore_above": 256,
"type": "keyword"
}
}
},
"price": {
"type": "double"
},
"created_at": {
"type": "date"
},
"description": {
"type": "text",
"fields": {
"keyword":{
"ignore_above": 256,
"type": "keyword"
}
}
},
"author":{
"type": "keyword"
}
}
}
}
2、批量插入数据
PUT /books/_doc/_bulk
{"index":{}}
{"title":"vue小白到大神","price":56.2,"created_at":"2022-01-23","description":"Java是一门面向对象的编程语言,不仅吸收了C++语言的各种优点,还摒弃了C++里难以理解的多继承、指针等概念,因此Java语言具有功能强大和简单易用两个特征。","author":"开始测试"}
{"index":{}}
{"title":"python菜鸟教程","price":56.2,"created_at":"2020-10-23","description":"Python 基础教程 Python 是一种解释型、面向对象、动态数据类型的高级程序设计语言。","author":"小华师兄"}
3、全量查询该索引数据
GET /books/_search
{
"query": {
"bool": {
"must": [
{
"match_all": {}
}
]
}
}
}
4、多字段分词检索、高亮、过滤查询
GET /books/_search
{
"query": {
"bool": {
"must": [
{
"multi_match": {
"query": "Java从入门到放弃",
"fields": ["*"]
}
}
],
"filter": [
{
"exists": {
"field": "title"
}
},
{
"exists": {
"field": "description"
}
}
]
}
},
"highlight": {
"post_tags": [""],
"pre_tags": [""],
"fields": {
"*":{}
}
}
}
结果展示:



