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缓存

     

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值