2 Match、Filter、排序、分页、全文检索、短语匹配、关键词高亮
作者:互联网
查索引内所有文档记录
GET /beauties/my/_search
GET /beauties/my/_search
{
"query":{
"match_all": {}
}
}
匹配、排序
GET /beauties/my/_search
{
"query": {
"match": {
"Name": "Ruru"
}
},
"sort": [
{"Age": "desc"}
]
}
筛选字段
GET /beauties/my/_search
{
"query": {
"match_all": {}
},
"_source":["Name","Age"]
}
分页
GET /beauties/my/_search
{
"query": {
"match_all": {}
},
"_source":["Name","Age"],
"from": 1,
"size": 2
}
bool filter、
GET /beauties/my/_search
{
"query": {
"bool": {
"must": {
"match": {
"Name": "Zhao"
}
},
"filter":{
"range": {
"Age": {
"gt": 19,
"lt":24
}
}
}
}
}
}
GET /beauties/my/5
POST /beauties/my/5/_update
{
"doc":{
"Desc":"Ruru Friend"
}
}
全文检索:会匹配Name的值,包含以下单词的,只要匹配一个单词就能搜出来,但score不一样
GET /beauties/my/_search
{
"query": {
"match": {
"Name": "Zhao Ruru Chang Aijing Wei"
}
}
}
短语搜索:必须匹配 Zhao Ruru才行。
对于Name=Zhao Ruru的记录,搜match_phrase=Zhao能搜出来,=Zha搜不出来
GET /beauties/my/_search
{
"query": {
"match_phrase": {
"Name": "Zhao Ruru"
}
}
}
高亮匹配的关键词。会在结果中,给关键词加上 em 标签
GET /beauties/my/_search
{
"query": {
"match_phrase": {
"Name": "Zhao"
}
},
"highlight": {
"fields": {
"Name":{}
}
}
}
标签:search,beauties,Name,GET,Filter,全文检索,match,my,Match 来源: https://www.cnblogs.com/cc299/p/11032796.html