码迷,mamicode.com
首页 > 其他好文 > 详细

ealsticsearch多种搜索方式

时间:2019-06-21 23:54:01      阅读:442      评论:0      收藏:0      [点我收藏+]

标签:amp   order   nba   als   rod   comm   doc   delete   desc   

增加
PUT /ecommerce/product/1
{ "name":"gaolujie yagao",
   "desc":"gaoxiao meibai",
   "price":30,
   "producer":"gaolujie producer",
   "tags":["meibai","fangzhu"]
}
PUT /ecommerce/product/2
{ "name":"jiajieshi yagao",
   "desc":"gaoxiao fangzhu",
   "price":25,
   "producer":"jiajieshi producer",
   "tags":["fangzhu"]
}
PUT /ecommerce/product/3
{ "name":"zhonghua yagao",
   "desc":"caoben zhiwu",
   "price":40,
   "producer":"zhonghua producer",
   "tags":["qingxin"]
}

查询

GET /ecommerce/product/1

修改

PUT /ecommerce/product/1
{ "name":"jiaqianban gaolujie yagao",
   "desc":"gaoxiao meibai",
   "price":30,
   "producer":"gaolujie producer",
   "tags":["meibai","fangzhu"]
}

这不是修改

PUT /ecommerce/product/1
{ "name":"jiaqianban gaolujie yagao"
}

修改

POST  /ecommerce/product/1/_update
{ 
  "doc":{
  "name":"gaolujie yagao"
  }
}

删除

DELETE /ecommerce/product/1

query string search

GET /ecommerce/product/_search
GET /ecommerce/product/_search?q=name:yagao&sort=price:desc

DSL

查询所有的数据

GET /ecommerce/product/_search
{
   "query": {
     "match_all": {}
   }

}

排序

GET /ecommerce/product/_search
{
   "query": {
     "match": {
       "name":"yagao"
     }
   },

   "sort": [
     {
       "price": {
         "order": "desc"
       }
     }
   ]

}

分页

GET /ecommerce/product/_search
{
  "query": {

    "match_all": {}
  },
  "from": 0,
  "size":1

}

查询指定的列

GET /ecommerce/product/_search
{

  "query": {

    "match_all": {}
  }
  ,
  "_source": ["name","price"]

}

对数据进行过滤


GET /ecommerce/product/_search
{
  "query": {

    "bool": {
      "must": [
        {"match": {
          "name": "yagao"
        }}]
      ,
      "filter": {
        "range": {
          "price": {
            "gt": 25,
            "lt": 50
          }
        }
      }
    }
  }

}

全文检索,会拆解搜索


PUT /ecommerce/product/5
{ "name":"special yagao",
   "desc":"special meibai",
   "price":50,
   "producer":"special yagao producer",
   "tags":["meibai"]
}

GET /ecommerce/product/_search
{

  "query": {

    "match": {
      "producer": "yagao producer"
    }
  }
}

短语搜索,不拆解,完全包含短语

GET /ecommerce/product/_search
{

  "query": {

    "match_phrase": {
      "producer": "yagao producer"
    }
  }
}

高亮


GET /ecommerce/product/_search
{
  "query": {

    "match": {
      "producer": "producer"
    }
  }
  ,

  "highlight": {
    "fields": {
      "producer":{}
    }
  }

}

ealsticsearch多种搜索方式

标签:amp   order   nba   als   rod   comm   doc   delete   desc   

原文地址:https://blog.51cto.com/395469372/2412182

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!