ELK之复杂查询和高亮查询


DELETE cyyindex
PUT cyyindex
{
"mappings": {
"properties": {
"name": {
"type": "keyword"
},
"address": {
"type": "text"
},
"age": {
"type": "integer"
}
}
}
}

GET /cyyindex
GET /cyyindex/_doc/_search

GET cyyindex/_doc/_search?q=name:"孙权"
GET cyyindex/_doc/_search?q=address:魏

GET cyyindex/_doc/_search
{
"query":{
"match":{
"name":"曹操"
}
}
}

GET cyyindex/_doc/_search
{
"query":{
"match":{
"address":"魏"
}
}
}

GET cyyindex/_doc/_search
{
"query":{
"match":{
"address":"魏"
}
},
"_source":["name","address","age"]
}

# 排序
GET cyyindex/_doc/_search
{
"query":{
"match":{
"address":"魏"
}
},
"_source":["name","address","age"],
"sort":[
{"age":{"order":"asc"}},
{"name":{"order":"asc"}}
]
}

# 分页查询
GET cyyindex/_doc/_search
{
"query":{
"match":{
"address":"魏国"
}
},
"_source":["name","address","age"],
"sort":[
{"age":{"order":"desc"}},
{"name":{"order":"asc"}}
],
"from":0,
"size":2
}

# where条件查询
# And
GET cyyindex/_doc/_search
{
"query":{
"bool":{
"must":[
{
"match":{
"address":"魏国"
}
},
{
"match":{
"name":"贾诩"
}
}
]
}
},
"_source":["name","address","age"],
"sort":[
{"age":{"order":"desc"}},
{"name":{"order":"asc"}}
],
"from":0,
"size":10
}

# OR
GET cyyindex/_doc/_search
{
"query":{
"bool":{
"should":[
{
"match":{
"address":"魏国"
}
},
{
"match":{
"name":"贾诩"
}
}
]
}
},
"_source":["name","address","age"],
"sort":[
{"age":{"order":"desc"}},
{"name":{"order":"asc"}}
],
"from":0,
"size":10
}

# NOT查询
GET cyyindex/_doc/_search
{
"query":{
"bool":{
"must_not":[
{
"match":{
"name":"曹操"
}
}
],
"filter":{
"range":{
"age":{
"gte":19,
"lte":29
}
}
}
}
},
"_source":["name","address","age"],
"sort":[
{"age":{"order":"desc"}},
{"name":{"order":"asc"}}
],
"from":0,
"size":10
}

# 高亮查询
GET cyyindex/_doc/_search
{
"query":{
"match":{"name":"曹操"}
},
"highlight":{

"fields": {
"name": {}
}
}
}


# 自定义高亮查询
GET cyyindex/_doc/_search
{
"query":{
"match":{"name":"曹操"}
},
"highlight":{

"pre_tags":"<p class='gaoliang'>",
"post_tags":"</p>",
"fields": {
"name": {}
}
}
}

 

 

# 插入数据
POST /cyyindex/_doc
{
"name":"曹操",
"address":"魏国",
"age":18
}

POST /cyyindex/_doc
{
"name":"贾诩",
"address":"魏国",
"age":19
}

POST /cyyindex/_doc
{
"name":"诸葛亮",
"address":"蜀国",
"age":18
}

POST /cyyindex/_doc
{
"name":"魏延",
"address":"蜀国",
"age":18
}

POST /cyyindex/_doc
{
"name":"关羽",
"address":"蜀国",
"age":18
}

POST /cyyindex/_doc
{
"name":"周瑜",
"address":"吴国",
"age":18
}

POST /cyyindex/_doc
{
"name":"孙权",
"address":"吴国",
"age":18
}

posted @ 2020-11-16 11:24  FiberHomer  阅读(227)  评论(0编辑  收藏  举报