zoukankan      html  css  js  c++  java
  • 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缓存

         

  • 相关阅读:
    怎么接音响
    怎样区分音箱与音响
    什么是卡盟
    小白晋级达人必备 电视接口使用介绍(4)
    液晶电视插有线电视信号线的是哪个接口 HDMI是什么接口
    Google 镜像站搜集
    屏幕检测
    网站引流
    夜神安卓模拟器
    html5模拟平抛运动
  • 原文地址:https://www.cnblogs.com/lexiaofei/p/6651828.html
Copyright © 2011-2022 走看看