美文网首页
elasticsearch常用查询语法

elasticsearch常用查询语法

作者: 若琳丶 | 来源:发表于2020-12-15 22:18 被阅读0次

    match

    会进行全文匹配

    {
        "query" : {
            "match": {
                "<field_name>": "<field_value>"
            }
        }
    }
    

    constant_score

    {
        "query": {
            "constant_score": {
                "filter": {
                    "match": {
                        "<field_name>": "<field_value>"
                    }
                },
                "boost": 2
            }
        }
    }
    

    should

    两个条件是 or 的关系

    {
        "query": {
            "bool": {
                "should": [
                    {
                        "match": {
                            "<field1_name>": "<field1_value>"
                        }
                    },
                    {
                        "match": {
                            "<field2_name>": "<field2_value>"
                        }
                    }
                ]
            }
        }
    }
    

    must

    可搭配 filter 进行过滤

    {
        "query": {
            "bool": {
                "must": [
                    {
                        "match": {
                            "<field1_name>": "<field1_value>"
                        }
                    },
                    {
                        "match": {
                            "<field2_name>": "<field2_value>"
                        }
                    }
                ],
                "filter": [
                    {
                        "term": {
                            "<field3_name>": "<field3_value>"
                        }
                    }
                ]
            }
        }
    }
    

    must_not

    {
        "query": {
            "bool": {
                "must_not": {
                    "term": {
                        "author": "瓦力"
                    }
                }
            }
        }
    }
    

    相关文章

      网友评论

          本文标题:elasticsearch常用查询语法

          本文链接:https://www.haomeiwen.com/subject/rhrggktx.html