ELK学习总结(3-2)elk的过滤查询

时间:2023-03-09 17:10:33
ELK学习总结(3-2)elk的过滤查询

和一般查询比较,filter查询:能够缓存数据在内存中,应该尽可能使用

建立测试数据

查看测试数据

1、filtered查询

GET /store/products/_search

{

"query":{

"filtered":{

"query": {

"match_all":{}

},

filter:{

"terms":{

"price":[10,20]

}

}

}

}

}

## 调用没有得到结果? 因为mapping没有指定not_analyzed

GET /store/products/_search

{

"query":{

"filtered":{

"query": {

"match_all":{}

},

filter:{

"term":{

"productID":"QW123"

}

}

}

}

}

GET /_analyze?text=QW123

--发现分析结果呈小写qw123

GET /store/_mapping

DELETE /store

##解决办法:重新建立一个映射,让productID处于not_analyzed模式

PUT /store

{

"mappings":{

"products":{

"properties": {

"productID":{

“type”:“string”,

“index”:“not_analyzed”

}

}

}

}

}

2、bool过滤查询,可以实现组合过滤查询 

"bool":{

"must":[],

     "should":[], 可以满足,也可以不满足

"must_not":[]

}

GET /store/products/_search

{

"query":{

"filtered":{

"filter": {

"bool":{

"should":[

{"term":{"price":20}},

{"term":{"productID":"SD12342"}}

],

"must_not":[

{"term":{"price":30}}

]

}

}

}

}

}

3、嵌套查询

4、and or not查询

and  并且,类似于must

or    或者,类似于should

not  不是,类似于must_not

GET /store/products/_search

{

"query":{

"filtered":{

"filter": {

"or":[

{"term":{"price":20}},

{"term":{"productID":"SD12342"}}

]

},

"query":{

"match_all":{}

}

}

}

}

5、range过滤查询

gt:>

lt:<

gte: >=

lte : <=

GET /store/products/_search

{

"query":{

"filtered":{

"filter": {

"range":{

"price":{

"gte":20,

"lt":50

}

}

}

}

}

}

6、过滤空和非空

exists

missing

7、cache缓存