基本查询 排序
http://localhost:9200/suoyintest3/
PSOT _search
{
"query": {
"match": {
"content": "返回"
}
},
"sort": {
"_score": "desc"
}
}
开启某个字段支持 fielddata 功能
http://localhost:9200/suoyintest3/_mapping/
put
{
"properties": {
"title": {
"type": "text",
"fielddata": true
}
}
}
然后根据 不存在这个字段的文档进行排序:
http://localhost:9200/suoyintest3/
post _search
{
"query": {
"match_all": {}
},
"sort": [
{
"content": {
"order": "desc",
"missing": "_last"
}
}
]
}
返回指定的字段,根据指定的字段排序,返回固定条数“”
http://localhost:9200/suoyintest3/
post _search
{
"query": {
"match_all": {}
},
"sort": {
"id": {
"order": "desc"
}
},
"_source": [
"title",
"id"
],
"size": 15
}
高亮查询:
http://localhost:9200/suoyintest3/
post _search
{
"query": {
"match": {
"content": "接口"
}
},
"highlight": {
"pre_tags": [
""
],
"post_tags": [
""
],
"fields": {
"content": {
"fragment_size": 150,
"number_of_fragments": 1
}
}
},
"size": 15
}
指定多个字段检索:
http://localhost:9200/suoyintest3/
post _search
{
"query": {
"multi_match": {
"query": "通过",
"fields": [
"title",
"content"
]
}
}
}
时间区间查询:
gte 大于等于
gt 大于
lte 小于等于
lt 小于
boost 权重 默认1.0
http://localhost:9200/suoyintest3/
put
先增加一个时间类型的 字段crtTime
{
"properties": {
"crtTime": {
"type": "date"
}
}
}
再进行查询
{
"query": {
"range": {
"crtTime": {
"gt": "2020-09-01",
"lt": "2022-01-01"
}
}
}
}
也可以使用now 函数 和时间函数:例如 查询当前两天内的:支持的单位有 y M w d h H m s
{
"query": {
"range": {
"crtTime": {
"gt": "now-2d",
"lt": "now"
}
}
}
}
模糊查询 wildcard 查询
支持* 和? * 号表示任意多个任意字符,? 代表任意一个字符
{
"query": {
"wildcard": {
"title.keyword": {
"value": "*通过*",
"boost": 10
}
}
}
}
{
"query": {
"wildcard": {
"title.keyword": {
"value": "集群健康状?,这是??",
"boost": 10
}
}
}
}
正则表达式查询:
{
"query": {
"regexp": {
"title": {
"value": "[移动|菜鸟]",
"boost": 10
}
}
}
}
多条件查询 bool:
{
"query": {
"bool": {
"must": {
"match": {
"title": "移动"
}
},
"must_not": {
"match": {
"title": "菜鸟"
}
}
}
}
}