zoukankan      html  css  js  c++  java
  • es filter 的使用

    批量创建数据

    GET /lib4/items/_bulk
    {"index":{"_id":1}}
    {"price":40,"itemID":"ID100123"}
    {"index":{"_id":2}}
    {"price":50,"itemID":"ID100124"}
    {"index":{"_id":3}}
    {"price":25,"itemID":"ID100125"}
    {"index":{"_id":4}}
    {"price":30,"itemID":"ID100126"}
    {"index":{"_id":5}}
    {"price":null,"itemID":"ID100127"}

    filter 不计算相关性,同时可以cache,因此filter的速度快于query

    过滤查询

    
    
    GET /lib4/items/_search

    {
    "query":{
            "bool":{
                "filter":[
                    {"term":
                        {"price":40}
                    }
                ]
            }
        }
    }

    text类型进行term查询的问题

    text类型数据,es默认会对此字段查询使用分词,

    
    
    GET /lib4/items/_search
    查不出数据
    {
        "query":{
            "bool":{
                "filter":[
                    {"term":
                        {"itemID":"ID100124"}
                    }
                ]
            }
        }
    }
    能查出数据
    {
        "query":{
            "bool":{
                "filter":[
                    {"term":
                        {"itemID":"id100124"}
                    }
                ]
            }
        }
    }

    bool 过滤查询

    {
        "bool":{
            "must":[], -- 必须满足的条件--and
            "should":[],-- 可以满足也可以不满足的条件--or
            "must_not":[]-- 不能满足的条件--not
        }
    }

    bool查询例子

    
    
    GET /lib4/items/_search
    {
        "query":{
                "bool":{
                    "should":[
                            {"term":{
                                "price":25
                            }},
                            {"term":{
                                "itemID":"id100123"
                            }}
                
                ],
                "must_not":[
                        {"term":{
                                "price":40
                            }}
                    ]
            }
        }
    
    }

    范围查询,gt -- > , lt -- < , gte -- >= , lte -- <=

    GET /lib4/items/_search
    {
        "query":{
                "bool":{
                    "filter":{
                        "range":{
                            "price":{
                                "gt":25,
                                "lt":50
                            }
                        }
                    }
            }
        }
    
    }

    字段存在查询

    GET /lib4/items/_search
    {
        "query":{
                "bool":{
                    "filter":{
                        "exists":{
                            "field":"price"
                        }
                    }
            }
        }
    
    }

    只有filter的查询,不评分

    GET /lib4/items/_search
    {
        "query":{
                "constant_score":{
                    "filter":{
                        "term":{
                            "price":30
                        }
                    }
            }
        }
    
    }
  • 相关阅读:
    jsp自定义标签
    用javascript获取屏幕高度和宽度等信息
    解决document.location.href下载文件时中文乱码
    centos7下的ifconfig命令未安装
    vmstat命令
    FPM打包工具使用
    nmap的使用
    检测硬件RDMA卡是否存在
    RDMA卡的检测方法
    硬件RDMA的驱动配置和测试
  • 原文地址:https://www.cnblogs.com/dongma/p/13611224.html
Copyright © 2011-2022 走看看