es 查询

条件查询

放在请求地址上

http://127.0.0.1:9200/shopping/_search?q=name:qingmu123

放在请求体中进行查询

GET请求


http://127.0.0.1:9200/shopping/_search

{
    "query":{
        "match":{
            "name":"qingmu123"
        }
    }
}

全量查询

GET请求


http://127.0.0.1:9200/shopping/_search
{
    "query":{
        "match_all":{
           
        }
    }
}

分页查询

GET请求

http://127.0.0.1:9200/shopping/_search
{
    "query":{
        "match_all":{
           
        }
    },
    "from":0,
    "size":2
}

指定展示某个字段

GET请求

http://127.0.0.1:9200/shopping/_search
{
    "query":{
        "match_all":{
           
        }
    },
    "from":0,
    "size":2,
    "_source":["name"]
}

排序

GET请求

http://127.0.0.1:9200/shopping/_search
{
    "query":{
        "match_all":{
           
        }
    },
    "from":0,
    "size":2,
    "_source":["name"],
    "sort":{
        "age":{
            "order":"desc"
        }
    }
}

多条件查询

and

http://127.0.0.1:9200/shopping/_search
{
    "query":{
        "bool":{
            "must":[{
                "match":{
                    "name":"小米"
                }
            },
            {
                "match":{
                    "age":18
                }
            }]
        }
    }
}

or

http://127.0.0.1:9200/shopping/_search
{
    "query":{
        "bool":{
            "should":[{
                "match":{
                    "name":"小米"
                }
            },
            {
                "match":{
                    "age":18
                }
            }]
        }
    }
}

filter

http://127.0.0.1:9200/shopping/_search
{
    "query":{
        "bool":{
            "must":[{
                "match":{
                    "name":"小米"
                }
            },
            {
                "match":{
                    "age":18
                }
            }
            ],
            "filter":{
                "rang":{
                    "age":{
                    }
                }
            }
        
        }
    }
}

全文检索

GET请求

http://127.0.0.1:9200/shopping/_search

{
    "query":{
        "match":{
         "name":"米"
        }
    }
}

完全匹配

GET请求

http://127.0.0.1:9200/shopping/_search

{
    "query":{
        "match_phrase":{
         "name":"米"
        }
    }
}

高亮

GET请求

http://127.0.0.1:9200/shopping/_search

{
    "query":{
        "match_phrase":{
         "name":"米"
        }
    },
    "highlight":{
        "fields":{
            "name":{}
        }
    }
}

聚合操作

posted @ 2022-02-14 08:58  King-DA  阅读(72)  评论(0)    收藏  举报