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

         

  • 相关阅读:
    《Microsoft Sql server 2008 Internals》读书笔记第六章Indexes:Internals and Management(4)
    《Microsoft Sql server 2008 Internals》读书笔记第六章Indexes:Internals and Management(9)
    《Microsoft Sql server 2008 Internals》读书笔记第六章Indexes:Internals and Management(3)
    《Microsoft Sql server 2008 Internals》读书笔记第六章Indexes:Internals and Management(5)
    《Microsoft Sql server 2008 Internals》读书笔记第六章Indexes:Internals and Management(7)
    vs2010正式版安装图解
    Winform部署mshtml程序集出错的一个解决方案
    InstallShield 2010集成.net Framework 4的安装包制作
    vs2010无法访问svn存储库的一次意外
    InstallShield集成.net Framework的安装包制作
  • 原文地址:https://www.cnblogs.com/lexiaofei/p/6651828.html
Copyright © 2020-2023  润新知