zoukankan      html  css  js  c++  java
  • elasticsearch查询should和must

    elasticsearch在should和must查询时不能精确查出数据,主要原因是在7.0版本后should查询时minimum_should_match默认为0,查出了非should条件中的数据。

    minimum_should_match可以控制查询精度,在should和must联合查询查询时必须使用,否则查不出精确的数据。

    {
        "size":20,
        "query":{
            "bool":{
                "should":[
                    {
                        "match_phrase":{
                            "Title":"关键词"
                        }
                    },
                    {
                        "match_phrase":{
                            "summary":"关键词"
                        }
                    },
                    {
                        "match_phrase":{
                            "Content":"关键词"
                        }
                    }
                ],
                "minimum_should_match":1,
                "must":{
                    "match_phrase":{
                        "categoryId":0
                    }
                }
            }
        }
    }

    minimum_should_match为1时,表示无管should有多少可选条件子句,至少满足1个条件。

    minimum_should_match为-1时,负数时,至少满足should可选子句的总数减去此数字应该是必需的。

    如果不使用minimum_should_match,还有一种解决方案。

    (categoryId=0&Title="关键词")||(categoryId=0&summary="关键词")||(categoryId=0&Content="关键词")

    {
        "size":20,
        "query":{
            "bool":{
                "should":[
                    {
                        "bool":{
                            "must":[
                                {
                                    "match_phrase":{
                                        "categoryId":0
                                    }
                                },
                                {
                                    "match_phrase":{
                                        "Title":"关键词"
                                    }
                                }
                            ]
                        }
                    },
                    {
                        "bool":{
                            "must":[
                                {
                                    "match_phrase":{
                                        "categoryId":0
                                    }
                                },
                                {
                                    "match_phrase":{
                                        "summary":"关键词"
                                    }
                                }
                            ]
                        }
                    },
                    {
                        "bool":{
                            "must":[
                                {
                                    "match_phrase":{
                                        "categoryId":0
                                    }
                                },
                                {
                                    "match_phrase":{
                                        "Content":"关键词"
                                    }
                                }
                            ]
                        }
                    }
                ]
            }
        }
    }
  • 相关阅读:
    [Swift] Swift3.0--GCD
    [Android Pro] Swift 3.0多线程
    [MAC OS ] UserDefaults
    [MAC OS] NSOpenPanel 使用
    [ IOS ] iOS-控制器View的创建和生命周期
    [ IOS ] 视图控制对象ViewController的生命周期
    [Android Pro] AtomicInteger的用法
    [MAC OS] 常用工具
    [MAC OS] NSButton tag 获取
    [MAC OS] XCode中的Debug View Hierarchy功能
  • 原文地址:https://www.cnblogs.com/yuejin/p/14684997.html
Copyright © 2011-2022 走看看