标签:排序 app pre lte 旅游 asc 没有 val desc
#
GET my_store/_search
{
"query": {
"match_all": {}
}
}
#添加索引
PUT /test2
{
"mappings": {
"properties": {
"name":{
"type": "text"
},
"age":{
"type": "long"
},
"brithday":{
"type": "date"
}
}
}
}
#查看索引
GET test2
#添加索引对应值
PUT /test3/_doc/1
{
"name":"玉玉",
"age":23,
"brithday":"2020-01-01"
}
#查看索引对应文档
GET test3/_doc/1
GET _cat/indices
#修改对应索引文档值
PUT /test3/_doc/1
{
"name":"玉玉11",
"age":23,
"brithday":"2020-01-01"
}
#更新对应索引文档值
POST /test3/_doc/1/_update
{
"doc": {
"name":"鱼鱼鱼"
}
}
#删除索引,以及对应的数据
DELETE test2
#添加数据
PUT /yu/user/1
{
"name":"yuyu",
"age":23,
"desc":"第一个数据源",
"tags":["技术宅","直男","温暖"]
}
PUT /yu/user/2
{
"name":"张三",
"age":6,
"desc":"第一个数据源",
"tags":["技术宅","旅游","温暖"]
}
PUT /yu/user/3
{
"name":"李四22",
"age":30,
"desc":"描述",
"tags":["靓仔","旅游","温暖"]
}
GET yu/user/3
POST /yu/user/3/_update
{
"doc": {
"name":"宇宇"
}
}
GET yu/user/_search
#只显示name,age字段
GET yu/user/_search
{
"query": {
"match": {
"name": "宇宇"
}
},
"_source": ["name","age"]
}
#排序
GET yu/user/_search
{
"query": {
"match_all": {
}
},
"sort": [
{
"age": {
"order": "asc"
}
}
]
}
#分页
GET yu/user/_search
{
"query": {
"match_all": {
}
},
"from": 0,
"size": 1
}
#多命令精确查询
GET yu/user/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"name": "yuyu"
}
}
]
}
}
}
#模糊匹配查询
GET yu/user/_search
{
"query": {
"match": {
"desc": "第一个"
}
}
}
#_source过滤显示字段,只显示name,desc字段
GET yu/user/_search
{
"query": {
"match": {
"desc": "第一个"
}
}
,
"_source": ["name","desc"]
}
#sort排序,通过age进行排序
GET yu/user/_search
{
"query": {
"match": {
"desc": "第一个"
}
}
,
"sort": [
{
"age": {
"order": "desc"
}
}
]
}
#from,size分页 查询 from从第几个数据开始
#size每页显示多少个
GET yu/user/_search
{
"query": {
"match": {
"desc": "第一个"
}
}
,
"sort": [
{
"age": {
"order": "desc"
}
}
]
,
"from": 0,
"size": 10
}
#布尔值查询
#must(类似and) 所有条件都要满足
GET yu/user/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"desc": "第一"
}
},
{
"match": {
"age": "6"
}
}
]
}
}
}
#should(类似or,所有条件满足其一即可 )
GET yu/user/_search
{
"query": {
"bool": {
"should": [
{
"match": {
"desc": "第一"
}
},
{
"match": {
"age": "6"
}
}
]
}
}
}
#must_not(类似于not) 年林不是6岁的人
GET yu/user/_search
{
"query": {
"bool": {
"must_not": [
{
"match": {
"age": "6"
}
}
]
}
}
}
#filter 进行加条件过滤 年龄大于等于10岁的人
GET yu/user/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"desc": "第一"
}
}
],
"filter": {
"range": {
"age": {
"gte": 10
}
}
}
}
}
}
#匹配多个条件 多个条件使用空格隔开即可
#只要满足其一就可以查出,通过分值高低判断
GET yu/user/_search
{
"query": {
"match": {
"tags": "技术 男"
}
}
}
#精确查询
#term查询是直接通过倒排索引指定的词条进行精确的查找
#
#添加索引
PUT testdb2
{
"mappings": {
"properties": {
"name":{
"type": "text"
},
"desc":{
"type": "keyword"
}
}
}
}
#插入数据
PUT testdb2/_doc/1
{
"name":"测试讲java name",
"desc":"测试讲java desc"
}
PUT testdb2/_doc/2
{
"name":"测试讲java name",
"desc":"测试讲java desc2"
}
#使用分词器查询
#没有被分析
GET _analyze
{
"analyzer": "keyword",
"text":"测试讲java name"
}
#可以看到被拆分了
GET _analyze
{
"analyzer": "standard",
"text":"测试讲java"
}
#keyword类型的字段,不会被分词器解析,只能全文匹配
GET testdb2/_search
{
"query": {
"term": {
"desc": {
"value": "测试讲java desc"
}
}
}
}
#精确查询
PUT testdb2/_doc/3
{
"t1":11,
"t2":"2020-01-01"
}
GET testdb2/_search
{
"query": {
"bool": {
"should": [
{
"term": {
"t1": {
"value": "11"
}
}
}
]
}
}
}
#高亮显示
GET testdb2/_search
{
"query": {
"match": {
"name": "测试"
}
},
"highlight": {
"fields": {
"name":{}
}
}
}
#自定义高亮显示
GET testdb2/_search
{
"query": {
"match": {
"name": "测试"
}
},
"highlight": {
"pre_tags": "<p class=‘key‘ style=‘color:red‘>",
"post_tags": "</p>",
"fields": {
"name":{}
}
}
}
标签:排序 app pre lte 旅游 asc 没有 val desc
原文地址:https://www.cnblogs.com/ymj2018/p/14081457.html