es search示例

Search调用

/index1/_search

/index1,index2/_search

/index*/_search

URI Search

get /users/_search?q=is&df=message&sort=post_date:desc&from=3&size=10&timeout=1s
{
  "profile":true
}
  1. q:查询字符串
  2. df:查询字段,不指定默认所有字段
  3. sort:排序字段(from,size,分页相关)
  4. profile:true/false:展示search过程

另外一种形式:

get /users/_search?q=message:is

search message,包含is字符

Request Body Search

get /users/_search
{
  "profile":true,
  "sort":
  {
    "post_date":
    {
      "order":"desc"
    }
  },
  "from":"3",
  "size":1,
  "query":{
    "match_all": {}
  }
}
get /users/_search
{
  "profile":true,
  "sort":
  {
    "post_date":
    {
      "order":"desc"
    }
  },
  "from":"3",
  "query":{
    "bool": {
       "must": [
         {"match": 
           {
           "user": "mike"
           }
         },
         {"match_phrase":
           {
             "message": "is"
           }
         }
       ]
    }
  }
}
posted @ 2021-03-07 19:06  xuan_wu  阅读(104)  评论(0编辑  收藏  举报