匹配
按照条件匹配
精准匹配
区间范围匹配
匹配字段过滤
多条件查询
高亮查询
//创建索引
PUT /test/type/1
{
"name":"小白说elasticseach",
"age":"28"
}
//设置属性
PUT /test1
{
"mappings": {
"properties": {
"name": {
"type":"text"
},
"birthday": {
"type":"date"
}
}
}
}
//查询
GET test
//新增
PUT /test3/_doc/1
{
"name":"小白",
"age":"28",
"brithday":"1997-06-08"
}
GET test3
//健康
GET _cat/health
//版本
GET _cat/indices?v
//更新
POST /test3/_doc/1/_update
{
"doc":{
"age":"66"
}
}
//删除
DELETE test1
//操作文档
PUT /xiaobai/user/1
{
"name":"小白",
"age":23,
"des":"elasticsearch",
"tags":["吹","拉","谈","唱"]
}
PUT /xiaobai/user/2
{
"name":"小艾",
"age":25,
"des":"Kibana",
"tags":["琴","棋","书","画"]
}
PUT /xiaobai/user/4
{
"name":"小水",
"age":28,
"des":"ik",
"tags":["偷","歼","耍","滑"]
}
GET xiaobai/user/1
POST xiaobai/user/1/_update
{
"doc":{
"age": 28
}
}
//查询
GET xiaobai/user/_search?q=name:小
//指定字段查询
GET xiaobai/user/_search
{
"query": {
"match": {
"name": "小白"
}
},
"_source": ["name","tags"]
}
//倒叙查询
GET xiaobai/user/_search
{
"query": {
"match": {
"name": "小白"
}
},
"sort": [
{
"age": {
"order": "desc"
}
}
]
}
//分页查询
GET xiaobai/user/_search
{
"query": {
"match": {
"name": "小白"
}
},
"sort": [
{
"age": {
"order": "desc"
}
}
],
"from": 0,
"size": 2
}
//多条件查询(and)
GET xiaobai/user/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"name": "白"
}
},
{
"match": {
"age": "28"
}
}
]
}
}
}
//(or) should 查询
GET xiaobai/user/_search
{
"query": {
"bool": {
"should": [
{
"match": {
"name": "白"
}
},
{
"match": {
"age": "28"
}
}
]
}
}
}
//不包含查询 (not)
GET xiaobai/user/_search
{
"query": {
"bool": {
"must_not": [
{
"match": {
"age": "3"
}
}
]
}
}
}
//过滤查询
//gt 大于
//gte 大于等于
//lt 小于
//lte 小于等于
GET xiaobai/user/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"name": "小白"
}
}
],
"filter":{
"range": {
"age": {
"gte": 0,
"lte": 10
}
}
}
}
}
}
//多匹配查询
GET xiaobai/user/_search
{
"query": {
"match": {
"tags": "偷 画"
}
}
}
//精确查询(倒排索引)
GET xiaobai/user/_search
{
"query": {
"term": {
"name": {
"value": "小水"
}
}
}
}
//高亮查询
GET xiaobai/user/_search
{
"query": {
"term": {
"name": {
"value": "小"
}
}
},
"highlight": {
"pre_tags": "<p color=red> ",
"post_tags": "</p>",
"fields": {
"name":{}
}
}
}
?
|