ElasticSearch常见用法 常见的ElasticSearch用法(4)
导读:ElasticSearch常见用法,GET /products/_search{ "query": { "multi_match": { "query": "iphone13 毫", "fields": ["title","description"] } }}注意: 字段类型分词,将查询条件分词之后进行查询改字段 如果该字
ElasticSearch常见用法
GET /products/_search
{
"query": {
"multi_match": {
"query": "iphone13 毫",
"fields": ["title","description"]
}
}
}
注意: 字段类型分词,将查询条件分词之后进行查询改字段 如果该字段不分词就会将查询条件作为整体进行查询
10、默认字段分词查询[query_string]
GET /products/_search
{
"query": {
"query_string": {
"default_field": "description",
"query": "屏幕真的非常不错"
}
}
}
注意: 查询字段分词就将查询条件分词查询 查询字段不分词将查询条件不分词查询
11、高亮查询[highlight]
GET /products/_search
{
"query": {
"query_string": {
"default_field": "description",
"query": "屏幕真的非常不错"
}
}
}
注意: 查询字段分词就将查询条件分词查询 查询字段不分词将查询条件不分词查询(1)highlight 关键字: 可以让符合条件的文档中的关键词高亮
GET /products/_search
{
"query": {
"term": {
"description": {
"value": "iphone"
}
}
},
"highlight": {
"fields": {
"*":{}
}
}
}
(2)自定义高亮html标签: 可以在highlight中使用pre_tags和post_tags
GET /products/_search
{
"query": {
"term": {
"description": {
"value": "iphone"
}
}
},
"highlight": {
"post_tags": ["</span>"],
"pre_tags": ["<span style='color:red'>"],
"fields": {
"*":{}
}
}
}
(3)多字段高亮 使用require_field_match开启多个字段高亮
GET /products/_search
{
"query": {
"term": {
"description": {
"value": "iphone"
}
}
},
"highlight": {
"require_field_match": "false",
"post_tags": ["</span>"],
"pre_tags": ["<span style='color:red'>"],
"fields": {
"*":{}
}
}
}
12、返回指定条数[size]
size 关键字: 指定查询结果中返回指定条数。 默认返回值10条
GET /products/_search
{
"query": {
"match_all": {}
},
"size": 5
}
13、分页查询[form]
from 关键字: 用来指定起始返回位置,和size关键字连用可实现分页效果
GET /products/_search
{
"query": {
"match_all": {}
},
"size": 5,
"from": 0
}
14、指定字段排序[sort]
GET /products/_search
{
"query": {
"match_all": {}
},
"sort": [
{
"price": {
"order": "desc"
}
}
]
}
15、返回指定字段[_source]
GET /products/_search
{
"query": {
"match_all": {}
},
"sort": [
{
"price": {
"order": "desc"
}
}
]
}_source 关键字: 是一个数组,在数组中用来指定展示那些字段
GET /products/_search
{
"query": {
"match_all": {}
},
"_source": ["title","description"]
}
上面IT袋网为您介绍的ElasticSearch常见用法的相关内容,希望对您有所帮助!
相关阅读
-
求生之路1怎么联机局域网 求生之路2本地服务器联机教程
小编为你介绍求生之路1怎么联机局域网和求生之路2本地服务器联机教程方面的讲解,下面来一起了解一下吧。 说到玩游戏,相信很多小伙伴都会在自己下班后的休息时间里,或者是周末宅在
-
dreamweaver新手教程快速入门 学生个人网页制作html
今日小编为你讲解学生个人网页制作html和dreamweaver新手教程快速入门的内容,下面为您详细介绍 伴随着互联网时代的到来,网页制作已经成为越来越多人感兴趣的一项技能。学习网页制作也成
-
什么是微服务、容器和Kubernetes
今日重点为您介绍什么是微服务、容器和Kubernetes的电脑方面的小经验,下面IT袋网为您详细介绍 什么是微服务? 什么是微服务?你应该使用微服务吗?微服务与容器和 Kubernetes 有什么关系?
-
OpenSSL命令详解:一篇全面深入的教程
全面的为您讲解OpenSSL命令详解的相关介绍,具体介绍如下: OpenSSL是一个开源项目,提供了一个健壮、全特性且高度灵活的工具包,主要用于安全传输协议和加密算法的实现。 在本文中,我们


