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

         

  • 相关阅读:
    Solr使用初探——SolrJ的使用
    Solr使用初探——Solr的安装环境与配置
    solr教程,值得刚接触搜索开发人员一看
    2013已过去,迎来2014,我们该如何规划自己的生活及职业生涯
    搭建集群必备:windows如何使用Xshell远程连接(SSH)Linux
    集群搭建:主机宽带拨号上网,虚拟机使用桥接模式,该如何ping通外网
    什么是Zookeeper,Zookeeper的作用是什么,在Hadoop及hbase中具体作用是什么
    如何搭建云平台,云平台搭建,需要学习什么云技术
    hadoop入门必备基础知识
    如何进行Hadoop二次开发指导视频下载
  • 原文地址:https://www.cnblogs.com/lexiaofei/p/6651828.html
Copyright © 2011-2022 走看看